Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting the real IP
Message
From
17/09/2013 10:15:34
 
 
To
17/09/2013 01:57:24
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01583370
Message ID:
01583393
Views:
32
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
Previous
Reply
Map
View

Click here to load this message in the networking platform