Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / VB

Whats My IP Address ?

5.00/5 (1 vote)
22 Sep 2011CPOL 10.2K  
On Vista/Win 7, I have seen code where only a single period is returned for (0). This makes sure you get the actual IP regardless of the system.Const IPPattern As String = ^d{1,3}.d{1,3}.d{1,3}.d{1,3}$With Dns.GetHostEntry(System.Environment.MachineName) Return...

On Vista/Win 7, I have seen code where only a single period is returned for (0). This makes sure you get the actual IP regardless of the system.


VB
Const IPPattern As String = "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$"

With Dns.GetHostEntry(System.Environment.MachineName)
    Return .AddressList.Where(Function(a) _
       Regex.IsMatch(a.ToString, IPPattern)).First.ToString
End With

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)