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

IP Grabber

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

Get All IP Addresses on Local Domain


Question:

I need to be able to run a script to log all active IP addresses on the local network.

Answer:

;*************************
copyright=""
copyright1=""
;*************************
;Setup

rev="3.4"

cr=strcat(Num2char(13),Num2Char(10))
TB=Num2Char(9)
sep="     " ;five spaces
sep1= " ==>> " 
appdir=DirGet ( )
lgfile="%appdir%\IPScan.log"

BoxTextColor(1,"17,60,123,0")
;BoxColor(1,"255,255,230",0)
AddExtender("wwipg34i.dll")
AddExtender("wwsop34i.DLL")
Decimals(2)


BoxesUp("200,200,800,800", @normal)
BoxCaption(1, '"IPScan %rev%" IP Address Range Scanner ')

oct1=""
oct2=""
oct3=""
scan1a=300
scan2a=1000
starts=0
ends=254
myaddress=""
ipout=""

gosub myaddress


:input
BoxDrawText(1, "70,70,1000,1000"," ", @TRUE,0)

MyDialogFormat=`WWWDLGED,6.1`

MyDialogCaption=`IPScan Setup`
MyDialogX=-01
MyDialogY=-01
MyDialogWidth=248
MyDialogHeight=156
MyDialogNumControls=021
MyDialogProcedure=`DEFAULT`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`
MyDialogConfig=4513660

MyDialog001=`011,131,062,012,PUSHBUTTON,DEFAULT,"Scan",1,11,32,DEFAULT,"255|255|255","0|128|0"`
MyDialog002=`165,131,062,012,PUSHBUTTON,DEFAULT,"Quit",0,13,DEFAULT,DEFAULT,"255|255|255","255|0|0"`
MyDialog003=`147,009,082,060,GROUPBOX,DEFAULT,"Timeout (ms)",DEFAULT,6,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog004=`033,095,026,012,EDITBOX,oct1,"192",DEFAULT,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog005=`063,095,026,012,EDITBOX,oct2,"168",DEFAULT,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog006=`183,097,026,012,EDITBOX,ends,"254",DEFAULT,5,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog007=`037,081,082,012,STATICTEXT,DEFAULT,"First Three Segments",DEFAULT,10,0,DEFAULT,DEFAULT,DEFAULT`
MyDialog008=`033,109,024,012,STATICTEXT,DEFAULT,"0 to 254",DEFAULT,25,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog009=`065,109,024,012,STATICTEXT,DEFAULT,"0 to 254",DEFAULT,25,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog010=`095,109,024,012,STATICTEXT,DEFAULT,"0 to 254",DEFAULT,25,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog011=`091,131,058,012,PUSHBUTTON,DEFAULT,"View Log",333,12,DEFAULT,Default,"255|255|255","0|0|255"`
MyDialog012=`093,095,026,012,EDITBOX,oct3,"100",DEFAULT,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog013=`139,097,026,012,EDITBOX,starts,"1",DEFAULT,4,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog014=`165,083,024,010,STATICTEXT,DEFAULT,"Range",DEFAULT,25,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog015=`167,099,012,012,STATICTEXT,DEFAULT,"< - >",DEFAULT,19,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog016=`019,019,104,042,VARYTEXT,myaddress,DEFAULT,DEFAULT,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog017=`009,009,130,060,GROUPBOX,DEFAULT,"This Computers IP Address(es)",DEFAULT,21,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog018=`153,039,024,012,EDITBOX,scan2a,"Scan2a",DEFAULT,18,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog019=`181,027,026,012,STATICTEXT,DEFAULT,"Ping",DEFAULT,17,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog020=`179,043,040,012,STATICTEXT,DEFAULT,"DNS Lookup",DEFAULT,17,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog021=`153,023,024,012,EDITBOX,scan1a,"Scan1a",DEFAULT,18,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("MyDialog",1)


BoxDrawText(1, "50,50,1000,1000","Scanning... ", @TRUE,0)
;debug(@on)
if buttonpushed=="333" then goto log

if oct1 <0 | oct1 >254 |strlen(oct1)>3 
oct1=""
beep
TimeDelay(.3)
beep
goto input
end if

if oct2 <0 | oct2 >254  |strlen(oct2)>3
oct2=""
beep
TimeDelay(.3)
beep
goto input
end if

if oct3 <0 | oct3 >254  |strlen(oct2)>3
oct3=""
beep
TimeDelay(.3)
beep
goto input
end if

if starts <0 | starts >254  |strlen(starts)>3
starts=""
beep
TimeDelay(.3)
beep
goto input
end if

if ends <0 | ends >254  |strlen(ends)>3
ends=""
beep
TimeDelay(.3)
beep
goto input
end if

if scan1a <100 then scan1a =100
if scan2a <200 then scan2a =200
scan1 = scan1a * .001
scan2 = scan2a * .001


now=timeymdhms()
xy=strcat(oct1,".",oct2,".",oct3,".")
range=strcat("Scaning ",xy,starts," to ",xy,ends)
line0=@cr
line1="++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
line2=strcat("  ",now,@tab,range)
output=FileOpen(lgfile,"APPEND")
         FileWrite(output,line0)
			FileWrite(output,line1)
			FileWrite(output,line2)
			FileClose(output)



tot=0 
ip=""
astatusbar(0,"IPScan",range,ends,0)
		BoxDrawText(1, "50,20,1000,1000","Finding IP Addresses in Use", @TRUE,0)
for xx=starts to ends
BoxDataTag(1, "tag1")
	zz=strcat(xy,xx)
	yy=ipPing(zz,scan1)
;	if yy!=1
	if yy==1
		tot=tot+1
			BoxDrawText(1, "50,20,1000,1000","Last of %tot% IP Address(es) Found:", @TRUE,0)
		host=ipAddr2Host(zz,scan2)
		host=StrUpper(host)
		if host =="" then host="UnResolved"
		ip=strcat(zz,@tab,@tab," ==> ",host)   
;		ip=strcat(xy,zz,@tab,@tab," ==> ",host)   
		ipout=strcat(@tab,ip)
		BoxDrawText(1, "70,70,1000,1000",ip, @TRUE,0)
		output=FileOpen(lgfile,"APPEND")
	        FileWrite(output,ipout)
	        FileClose(output)
	endif

astatusbar(1,range,"Scanning %ZZ%",ends,xx)

	BoxDataClear(1, "tag1")
next 

astatusbar(2,"IPScan","Scaning %starts% to %ends%",ends,0)
BoxCaption(1, '"IPScan" IP Address Range Scanner')
now=timeymdhms()
line1=strcat("  ",now,"   Scan Complete",@tab,tot, " Devices Found")
output=FileOpen(lgfile,"APPEND")
        FileWrite(output,line1)
        FileClose(output)
;	BoxDrawText(1, "50,50,1000,1000","Scan Complete", @TRUE,0)
		BoxDrawText(1, "50,20,1000,1000","", @TRUE,0)


:log
BoxDrawText(1, "001,300,1000,1000", "Generating Log Info. Please Wait... ",@TRUE, 1)

if fileexist("%lgfile%")
else
message("IPScan Log"," There is No Log File Yet")
goto input
endif


fs=FileSize(lgfile)
bb=BinaryAlloc(fs)
BinaryRead(bb,lgfile)
log=BinaryPeekStr(bb,0,fs)
BinaryFree(bb)
fs=fs/1000

lgnumber=(ItemCount(log, @CR)-1)
	BoxDrawText(1, "001,300,1000,1000", "",@TRUE, 1)

platform=WinMetrics(-4)
if platform == 5   ;windows 95 Ver
	if fs >="30" then pause("The Log Is Almost Full", "The Log File Is %fs% KB In Size With %lgnumber% Lines%CR%%cr%Our Limit in Windows 9x and ME Size Limit is about 32K%CR%%CR%%CR%Please Delete the Log File!")
	else
	if fs >="225" then pause("The Log Is Almost Full", "The Log File Is %fs% KB In Size With %lgnumber% Lines%CR%%cr%Our Limit in Windows NT, 2000 and XP Size Limit is about 250K%CR%%CR%%CR%Please Delete the Log File!")
	endif
	BoxDrawText(1, "001,800,1000,1000", "Number of Entries in Log:  %lgnumber%",@TRUE,1)



;*** IPScan LOG DIALOG
movlogFormat=`WWWDLGED,6.1`

movlogCaption=`***                                                                               IPScan Log                                                                                   ***`
movlogX=3000
movlogY=3000
movlogWidth=338
movlogHeight=204
movlogNumControls=005
movlogProcedure=`DEFAULT`
movlogFont=`DEFAULT`
movlogTextColor=`DEFAULT`
movlogBackground=`DEFAULT,DEFAULT`
movlogConfig=0

movlog001=`009,179,098,012,PUSHBUTTON,DEFAULT,"Return",1,1,32,"Arial|8192|40|34","255|255|255","0|128|0"`
movlog002=`011,023,314,148,MULTILINEBOX,log,"Multiline edit 1",DEFAULT,4,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
movlog003=`225,179,098,012,PUSHBUTTON,DEFAULT,"Delete Log",666,3,DEFAULT,"Arial|8192|40|34","255|255|255","128|0|0"`
movlog004=`051,003,234,012,EDITBOX,lgfile,"Edit 1",DEFAULT,100,8,DEFAULT,DEFAULT,DEFAULT`
movlog005=`117,179,098,012,PUSHBUTTON,DEFAULT,"Print Log",333,2,0,"Arial|8192|40|34","255|255|255","0|0|255"`

ButtonPushed=Dialog("movlog",1)


if buttonpushed =="666"
if askyesno ("Delete Log?", "Are You Sure You Want To Delete the IPScan Log?") then filedelete("%lgfile%")
endif

If buttonpushed =="333"
   If AskYesNo ("Print Log?", "Are You Sure You Want To Print the IPScan Log?")
      Run("notepad.exe",StrCat("/p ",lgfile))   ; Change to RunHide after debugged.
   EndIf
EndIf


BoxDrawText(1, "001,300,1000,1000", "Generating Log Info. Please Wait... ",@TRUE, 1)

goto input

exit

:myaddress
ips=ipGetAddress()
count=ItemCount(ips,@tab)
for xx=1 to count
   thisipstring=ItemExtract(xx,ips,@tab)
   myip=ItemExtract(1,thisipstring,"|")
		if myip=="127.0.0.1" then continue
		if myip=="0.0.0.0" then continue
	  myaddress=strcat (myaddress,myip,@cr)
next
return

Article ID:   W15838
File Created: 2017:07:28:13:58:30
Last Updated: 2004:03:30:15:41:04