WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

WinInet
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Get Real Internet Address


Question:

Creating a script to check a host of things on our client desktops out in the field. One of the things that I'd like to get is the real Internet address being used by the host instead of a NAT provided internal address. In other words, if the host is sitting behind a firewall with address of say 192.168.0.100 and is surfing the internet with address 4.222.45.63, I'd like to get the latter address. Is there a function to do this? If there isn't, I was thinking of going to a site such as www.ipchicken.com to get the real world address from the web page by searching through the text of the web page. My issue then becomes how do I search for a string that can can be any number in the pattern of www.xxx.yyy.zzz.

Answer:

You could use this to get the IP information from www.whatismyip.com. You need the WinInet Extender. You could adopt this to get it from your other website if you wanted.

addextender("wwint34i.dll")
tophandle=iBegin(0,"","")
connecthandle=iHostConnect(tophandle, "www.whatismyip.com", @HTTP, "", "")
datahandle=iHttpInit(connecthandle, "GET", "/", "",0)
if datahandle==0
   err=iGetLastError()
   Message("Last Error",err)
   iClose(tophandle)
   exit
endif
;Make sure to allocate large enough buffer to hold the entire file
size=10000
buf=BinaryAlloc(size)
;Get address of buffer
bufaddr=IntControl (42, buf, 0, 0, 0)
BinaryEodSet(buf, size)
rslt=iHttpOpen(datahandle, "", 0,0)
if rslt=="ERROR" || rslt!=200 
   if rslt == "ERROR" 
       errstr = "WinInet Error"
       rslt = iGetLastError()
   else
       errstr = "HTTP Error"
   endif

   Message(errstr,rslt)
   iClose(tophandle)
   exit
endif 

strToLocate = "Your IP is "
Start = strLen(StrToLocate)
CharEnd = "<"

iReadDataBuf(datahandle,bufaddr,size)
str=BinaryPeekStr(buf, 0, size)
LocateStart= StrIndex(str, strToLocate, 1, @fwdscan) + Start
LocateEnd = strscan(str,CharEnd,LocateStart,@fwdscan)
Length = LocateEnd - LocateStart
IPADDRESS = strsub(str,LocateStart,Length)

Message("The IP of this machine is",IPAddress)

iClose(datahandle)
iClose(tophandle)
exit


Article ID:   W16885
File Created: 2017:07:28:12:58:46
Last Updated: 2007:07:03:13:26:42