Click here to Skip to main content
15,887,444 members
Articles / Programming Languages / Visual Basic
Tip/Trick

Whats My IP Address ?

Rate me:
Please Sign up or sign in to vote.
4.50/5 (6 votes)
13 Sep 2011CPOL 65.3K   4   6
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)


Written By
Software Developer (Senior)
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionThanks so much Pin
SafeerArabian5-Apr-13 17:59
professionalSafeerArabian5-Apr-13 17:59 
Generalhttp://automation.whatismyip.com/n09230945.asp doesn't work ... Pin
kiquenet.com21-Nov-11 20:30
professionalkiquenet.com21-Nov-11 20:30 
GeneralReason for my vote of 4 Thanks for the Code lines. Pin
Member 432084427-Sep-11 8:24
Member 432084427-Sep-11 8:24 
GeneralReason for my vote of 4 Thanks. Pin
Member 432084427-Sep-11 8:15
Member 432084427-Sep-11 8:15 
GeneralReason for my vote of 3 good one Pin
HM India27-Sep-11 3:46
professionalHM India27-Sep-11 3:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.