Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB program to get external IP address of a PC??? 2

Status
Not open for further replies.

Paladyr

Programmer
Apr 22, 2001
508
US
Does anyone have any example code that shows how to get the external IP address of the PC running the program? Thanks!
 
or of course,

you could just read the LocalIP property of the MSWinsock Control!

Code:
dim strMyComputerIP as string

strMyComputerIP = Winsock1.LocalIP

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
This would be on a PC that is on a LAN, so the winsock control would give me the "local" and not "external" ip. At least I think that is what would happen.
 
<Caveman Technology>
An extremely crude method might be to IPCONFIG /ALL to a text file and then parse that for the information you want.
</Caveman Technology>

Andy
&quot;Logic is invincible because in order to combat logic it is necessary to use logic.&quot; -- Pierre Boutroux
&quot;A computer program does what you tell it to do, not what you want it to do.&quot; -- Greer's Third Law
 
Just tried the microsoft article, that's definitely an internal IP. Any other ideas?
 
IPCONFIG would give me the internal IP as well. Tough question eh? :p.
 
' Assumes you have an Internet Transfer Control on your form
Private Function getExternalIP() As String
Dim myDoc As String

myDoc = Inet1.OpenURL(&quot; With New RegExp
.MultiLine = True
.Pattern = &quot;(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})&quot;
If .Test(myDoc) Then
getExternalIP = .Execute(myDoc).Item(0).SubMatches(0)
End If
End With
End Function
 
Sorry. Should have said. You need to add a reference toto the Microsoft VBScript Regular Expressions Library
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top