Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How can I obtain my public IP
Message
From
22/03/2008 10:17:30
 
 
To
22/03/2008 09:26:42
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01304542
Message ID:
01304552
Views:
15
thank you all
Alessio
>
>?GetPublicIpAddress()
>
>********************************************************************************
>Function GetPublicIpAddress()
>********************************************************************************
>*!* Returns public IP address
>*!* Works under all conditions, routers, proxies, etc.
>*!* Works in all Windows versions from 95 to Vista
>*!* Downloads a file from a public HTTP server
>
>	#Define ERROR_SUCCESS	0
>
>	Local;
>		m.lcUrl As String, ;
>		m.lcFile As String, ;
>		m.lcIP As String
>
>*!* Generate a random Temp file name:
>	m.lcFile = Addbs(Sys(2023)) + Sys(3)
>
>*!* Add fake parameter to avoid web caching:
>	m.lcUrl = "http://checkip.dyndns.org" + "?" + Sys(3)
>
>*!* Set default value to return if API call fails:
>	m.lcIP = "0.0.0.0"
>
>*!* Attemp to download file:
>	If apiURLDownloadToFile(0, m.lcUrl, m.lcFile, 0, 0) = ERROR_SUCCESS Then
>*!* Check if file was created:
>		If File(m.lcFile) Then
>*!* Extract IP from file:
>			m.lcIP = Substr(Filetostr(m.lcFile), 77)
>			m.lcIP = Left(m.lcIP, Len(m.lcIP) - 16)
>			Delete File (m.lcFile)
>		Endif
>	Endif
>
>	Return m.lcIP
>Endfunc
>
>********************************************************************************
>Function apiURLDownloadToFile(m.pCaller, m.szURL, m.szFileName, m.dwReserved, m.lpfnCB)
>********************************************************************************
>	Declare Integer URLDownloadToFile In urlmon.Dll As apiURLDownloadToFile;
>		Integer pCaller, ;
>		String szURL, ;
>		String szFileName, ;
>		Integer dwReserved, ;
>		Integer lpfnCB
>	Return apiURLDownloadToFile(m.pCaller, m.szURL, m.szFileName, m.dwReserved, m.lpfnCB)
>Endfunc
>
Previous
Reply
Map
View

Click here to load this message in the networking platform