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

Whats My IP Address ?

4.50/5 (6 votes)
13 Sep 2011CPOL 66.4K  
Different Method(s) to Find IP Address?
Method 1

VB
Imports System.Net

'--------------------

Dim _HostName As String = Dns.GetHostName

MsgBox(_HostName)

'--------------------

Dim _IPHostEntry As IPHostEntry = Dns.GetHostByName(_HostName)

For Each _IP As IPAddress In _IPHostEntry.AddressList
   MsgBox(_IP.ToString)
Next
'--------------------

Method 2

VB
Imports System.IO
Imports System.Text
'--------------------

MsgBox(GetInternetIPAddress())
'--------------------

Private Function GetInternetIPAddress() As String
Try
Dim _ObjReq As HttpWebRequest = WebRequest.Create("http://automation.whatismyip.com/n09230945.asp")
Dim _ObjRes As HttpWebResponse = _ObjReq.GetResponse()
Dim _ObjStream As Stream = _ObjRes.GetResponseStream()
Dim _ObjSR As StreamReader = New StreamReader(_ObjStream)
Return _ObjSR.ReadToEnd()
Catch ex As Exception
   Return String.Empty
End Try
End Function

'--------------------

License

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