How to deterine the IP address of a URL

Everything else that doesn't fall into one of the other PB categories.
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

How to deterine the IP address of a URL

Post by TerryHough »

Is it possible to determine the current IP Address for a URL.

Example: What its the current IP Address for www.google.com ?

I've searched the forums and found a method to find the IP address of the local host. That may be a start.

Any help, code sample, or advice appreciated.

Terry
Max.
Enthusiast
Enthusiast
Posts: 225
Joined: Fri Apr 25, 2003 8:39 pm

Re: How to deterine the IP address of a URL

Post by Max. »

One solution that works for me is from PWS32

Code: Select all

; German forum: http://robsite.de/php/pureboard/viewtopic.php?t=834&highlight=
; 2. Mai 2003
; Author: PWS32

Structure HOSTENT 
h_name.l 
h_aliases.l 
h_addrtype.w 
h_length.w 
h_addr_list.l 
EndStructure 


Procedure.s GetIPbyName (NameIP.s) 
  TheIPAdress.s 
  If InitNetwork() 
    pHostinfo = gethostbyname_(NameIP) 
    If pHostinfo = 0 
      TheIPAdress = "Unable to resolve domain name" 
    Else 
      CopyMemory (pHostinfo, hostinfo.HOSTENT, SizeOf(HOSTENT)) 
      If hostinfo\h_addrtype <> #AF_INET 
        MessageRequester("Info","A non-IP address was returned",0) 
      Else 
        While PeekL(hostinfo\h_addr_list+AdressNumber*4) 
          ipAddress = PeekL(hostinfo\h_addr_list+AdressNumber*4) 
          TheIPAdress = StrU(PeekB(ipAddress),0)+"."+StrU(PeekB(ipAddress+1),0)+"."+StrU(PeekB(ipAddress+2),0)+"."+StrU(PeekB(ipAddress+3),0) 
          AdressNumber+1 
        Wend 
      EndIf 
    EndIf 
  Else 
    MessageRequester("Info","Network can't be initialized",0) 
  EndIf 
  ProcedureReturn TheIPAdress 
EndProcedure 

Debug GetIPbyName ("www.google.de")
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

Thanks Max., that is almost exactly the code that I referenced from the
main forum that wasn't helping me at all.

But your example works great.

Thanks much,
Terry
Post Reply