Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Boudewijn Lutgerink
  Where is Boudewijn Lutgerink?
 Hoonaardstraat, Driel
 Netherlands
 Boudewijn Lutgerink
 To: mike castillo
  Where is mike castillo?
 Joo Seng Road, Singapore
 Philippines
 mike castillo
 Tags
Subject: RE: Get IP address from www.site.com
Thread ID: 50731 Message ID: 50823 # Views: 1 # Ratings: 0
Version: Visual FoxPro 8 Category: Win32API programming
Date: Monday, September 06, 2004 12:28:00 PM         
   


> Hi Pete!
> try this:
>
>
> DECLARE INTEGER WSACleanup IN ws2_32
> DECLARE STRING inet_ntoa IN ws2_32 INTEGER in_addr
> DECLARE INTEGER gethostbyname IN ws2_32 STRING host
> DECLARE INTEGER WSAStartup IN ws2_32 INTEGER wVerRq, STRING lpWSAData
> DECLARE RtlMoveMemory IN kernel32 As CopyMemory;
> 	STRING @Dest, INTEGER Src, INTEGER nLength
> 
> IF WSAStartup(0x202, Repli(Chr(0),512)) = 0 && initiates use of WS2_32.DLL
> 	? GetIP('www.foxite.com')
> 	= WSACleanup()
> ENDIF
> 
> 
> FUNCTION GetIP(cServer)
> * returns IP like 127.0.0.1 for a given host name like www.somewhere.com
> #DEFINE HOSTENT_SIZE 16
> 	LOCAL nStruct, nSize, cBuffer, nAddr, cIP
> 	nStruct = gethostbyname(cServer)
> 	IF nStruct = 0
> 	* not found in a host database; or not connected etc.
> 		RETURN '0.0.0.0'
> 	ENDIF
> 
> 	cBuffer = Repli(Chr(0), HOSTENT_SIZE)
> 	cIP = Repli(Chr(0), 4)
> 
> 	= CopyMemory(@cBuffer, nStruct, HOSTENT_SIZE)
> 	= CopyMemory(@cIP, buf2dword(SUBS(cBuffer,13,4)),4)
> 	= CopyMemory(@cIP, buf2dword(cIP),4)
> RETURN inet_ntoa(buf2dword(cIP))
> 
> FUNCTION buf2dword(lcBuffer)
> RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
> 	Bitlshift(Asc(SUBS(lcBuffer, 2,1)),8) +;
> 	Bitlshift(Asc(SUBS(lcBuffer, 3,1)),16) +;
> 	Bitlshift(Asc(SUBS(lcBuffer, 4,1)),24)
> 
> 

>
> hope this helps
Neat code. Straight to the well-guarded treasure box. Tx Mike!

Boudewijn LutgeĀ®ink
There are 10 types of people: Those that do understand binary calculations and those that do not.

ENTIRE THREAD

Get IP address from www.site.com Posted by Pete Sass @ 9/5/2004 8:02:10 PM
RE: Get IP address from www.site.com Posted by mike castillo @ 9/6/2004 11:57:56 AM
RE: Get IP address from www.site.com Posted by Boudewijn Lutgerink @ 9/6/2004 12:28:00 PM
RE: Get IP address from www.site.com Posted by Lucy Alice Pilanga @ 9/7/2004 3:11:49 AM
Get IP address from www.site.com "Thks Mike" Posted by Pete Sass @ 9/7/2004 1:29:32 PM