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

Get IP Address

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

Get IP Address - Netstat Method

Keywords:  IP address netstat  

Please note: The Ip Grabber Extender functions supercede, the example in this article.

Example courtesy of John Henry Miller: jhmiller@execpc.com

On some systems, you'll need to substitute the following syntax:

	RunWait("command.com","/c nbtstat.exe -n >%TempDir%\subnet.txt")
for the netstat.exe in the code below.

;Active Connections
;
;  Proto  Local Address		 Foreign Address	State
;  TCP	  206.63.11.252:1041	 206.63.11.1:139	ESTABLISHED

ipname="ipget.txt"
Dir=Environment("TEMP")
if dir=="" then dir=Environment("TMP")
if dir=="" then dir="C:\"
DirChange(dir)
;Change RunWait to RunHideWait AFTER you get it
;debugged.
Runwait("command.com","/c netstat.exe -r > %ipname%")
fs=Filesize(ipname)
bb=BinaryAlloc(fs)
BinaryRead(bb,ipname)
a=BinaryIndex(bb,0,"Active Connections",@fwdscan)
if a==0
    Pause("Error","Active Connections not found!")
EndIf
a=BinaryIndex(bb,a,"Proto",@fwdscan)
if a==0
    Pause("Error","Protocol not found!")
EndIf
a=BinaryIndex(bb,a,"TCP",@fwdscan)
if a==0
    Pause("Error","TCP not found!")
EndIf
a=a+4
while BinaryPeek(bb,a)==32
   a=a+1
endwhile
colon=BinaryIndex(bb,a,":",@fwdscan)
if colon>0
   ipaddr=BinaryPeekStr(bb,a,colon-a)
   Message("IP Address",ipaddr)
else
   Pause("Error","Ip address not found")
endif
FileDelete(ipname)

Exit

Article ID:   W12653
Filename:   Get IP Address - Netstat Method.txt
File Created: 2001:01:03:14:12:02
Last Updated: 2001:01:03:14:12:02