Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting the real IP
Message
De
17/09/2013 10:15:34
 
 
À
17/09/2013 01:57:24
Al Doman (En ligne)
M3 Enterprises Inc.
North Vancouver, Colombie Britannique, Canada
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01583370
Message ID:
01583393
Vues:
31
The code on that page was not fully functionable. I have adjusted it but it now returns always 127.0.0.1:
    ' Return the IP address
    Public Function GetIP() As String
        Dim lcIP As String = ""
        Dim loIPInterfaceProperties As System.Net.NetworkInformation.IPInterfaceProperties = Nothing
        Dim loNetworkInterface As System.Net.NetworkInformation.NetworkInterface = Nothing
        Dim loNetworkInterfaces As System.Net.NetworkInformation.NetworkInterface() = Nothing
        Dim loUnicastIPAddressInformation As System.Net.NetworkInformation.UnicastIPAddressInformation = Nothing
        Dim loUnicastIPAddressInformationCollection As System.Net.NetworkInformation.UnicastIPAddressInformationCollection = Nothing

        ' Initialization
        loNetworkInterfaces = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()

        ' For each network interface
        For Each loNetworkInterface In loNetworkInterfaces

            ' Initialization
            loIPInterfaceProperties = loNetworkInterface.GetIPProperties()
            loUnicastIPAddressInformationCollection = loIPInterfaceProperties.UnicastAddresses

            ' For each Unicast IP address
            For Each loUnicastIPAddressInformation In loIPInterfaceProperties.UnicastAddresses

                ' If this is the primary address
                If loUnicastIPAddressInformation.Address.AddressFamily = Net.Sockets.AddressFamily.InterNetwork Then
                    lcIP = loUnicastIPAddressInformation.Address.ToString()
                End If

            Next

        Next

        Return lcIP
    End Function
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform