Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting the real IP
Message
De
17/09/2013 12:27:38
 
 
À
17/09/2013 10:55:48
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:
01583425
Vues:
41
>This resolves the issue:
>
>
>    ' Return the IP address
>    Public Function GetIP() As String
>        Dim lcIP As String = ""
>        Dim loNetworkInterface As System.Net.NetworkInformation.NetworkInterface = Nothing
>        Dim loNetworkInterfaces As System.Net.NetworkInformation.NetworkInterface() = Nothing
>        Dim loUnicastIPAddressInformation As System.Net.NetworkInformation.UnicastIPAddressInformation = Nothing
>
>        ' Initialization
>        loNetworkInterfaces = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
>
>        ' For each network interface
>        For Each loNetworkInterface In loNetworkInterfaces
>
>            ' If this is our primary adapter
>            If loNetworkInterface.NetworkInterfaceType = System.Net.NetworkInformation.NetworkInterfaceType.Wireless80211 OrElse _
>             loNetworkInterface.NetworkInterfaceType = System.Net.NetworkInformation.NetworkInterfaceType.Ethernet Then
>
>                ' For each IP address
>                For Each loUnicastIPAddressInformation In loNetworkInterface.GetIPProperties().UnicastAddresses
>
>                    ' If this the primary IP address
>                    If loUnicastIPAddressInformation.Address.AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork Then
>                        lcIP = loUnicastIPAddressInformation.Address.ToString()
>                    End If
>
>                Next
>
>            End If
>
>        Next
>
>        Return lcIP
>    End Function
>
Are you sure that works. lcIP may be set multiple times and you will return just the last one. Is that what you want ?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform