Joe,
This does what you want:

********************
* Start of Program
*
Clear

Do DLL_Declare

If InitWinsock()
  Local lcLocalHost, lcLocalIP
  cHost="www.Microsoft.com"
  cHostIP = GetHostIP(cHost)

  ? "Host:", cHost
  ? "Host IP:", cHostIP

  = WSACleanup()
Endif
* End of Main

Function  GetHostIP (lcHostname)
  #Define HOSTENT_SIZE  16
  Local lcHOSTENTptr, lcHOSTENT, lnAddrlistPtr

  * address for the HOSTENT structure
  lcHOSTENTptr = gethostbyname(lcHostname)

  If lcHOSTENTptr <> 0
    lcHOSTENT = GetMemBuf (lcHOSTENTptr, HOSTENT_SIZE)

    * a pointer to a null-terminated list of addresses
    lnAddrlistPtr = buf2dword(Substr(lcHOSTENT, 13,4))
    Return GetIPfromHOSTENT (lnAddrlistPtr)
  Endif
  Return ""
Endfunc


Procedure  GetIPfromHOSTENT (lnAddrlistPtr)
  * retrieving IP address from the HOSTENT structure
  Local lnDataAddress, lcResult
  lnDataAddress = buf2dword(GetMemBuf (lnAddrlistPtr, 4))
  Return Iif(lnDataAddress <> 0, ;
    GetIPAddress(GetMemBuf(lnDataAddress,4)),"")
Endproc

Function  GetIPAddress (lcAddrBuf)
  * converts 4-characters string buffer
  * to the IP address string representation
  Local lcResult, ii
  lcResult = ""
  For ii=1 To 4
    lcResult = lcResult +;
    LTRIM(Str(Asc(Substr(lcAddrBuf, ii,1)))) + ;
      Iif(ii=4, "",".")
  Endfor
  Return  lcResult
Endfunc

Function  InitWinsock()
  * Initializing the Winsock service for the application
  #Define WSADATA_SIZE  398
  #Define WS_VERSION    514  && 0x0202
  Local lcWSADATAln, lnInitResult
  lcWSADATA = Repli(Chr(0), WSADATA_SIZE)
  lnInitResult = WSAStartup (WS_VERSION, @lcWSADATA)
  Return  (lnInitResult = 0)
Endfunc

Function  GetMemBuf (lnAddr, lnBufsize)
  Local lcBuffer
  lcBuffer = Repli(Chr(0), lnBufsize)
  = Heap2Str (@lcBuffer, lnAddr, lnBufsize)
  Return  lcBuffer
Endfunc

Function  buf2dword (lcBuffer)
  Return Asc(Substr(lcBuffer, 1,1)) + ;
    Asc(Substr(lcBuffer, 2,1)) * 256 +;
    Asc(Substr(lcBuffer, 3,1)) * 65536 +;
    Asc(Substr(lcBuffer, 4,1)) * 16777216
Endfunc


Procedure  DLL_Declare
  Declare Integer WSAStartup In ws2_32 Integer wVerRq, String @lpWSAData
  Declare Integer WSACleanup In ws2_32
  Declare Integer gethostbyname In ws2_32 String HostName

  Declare Integer gethostname In ws2_32;
    STRING @Name, Integer namelen

  Declare RtlMoveMemory In kernel32 As Heap2Str;
    STRING @Dest, Integer Src, Integer nLength

Endproc
*
*End of Program
*******

Dave Crozier

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Joe Yoder
Sent: 14 July 2008 21:20
To: [email protected]
Subject: Determining IP Address from Domain Name programmatically

I know I could do an nslookup redirected to a file and tear the file apart
to get the info but it seems there must be a more elegant approach.  An API
call?
 
TIA - Joe


--- StripMime Report -- processed MIME parts ---
multipart/alternative
  text/plain (text body -- kept)
  text/html
---

[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to