Page 1 of 1 1
Topic Options
#120915 - 2004-06-09 05:47 PM Script to execute program on 20 subnets
Jharper Offline
Fresh Scripter

Registered: 2003-07-29
Posts: 13
Hey guys,
My dilemma is that I need to write a script that runs through all of the IPs in the DHCP scope (24 bit mask / 50-254) in 20 different subnets and pass the IP to a program as a parameter. I can't decide the best way to do this. I know the very basics of KiX scripting but need a something basic to get me started. Any help would be much appreciated.

Thanks,
Jharper

Top
#120916 - 2004-06-09 05:54 PM Re: Script to execute program on 20 subnets
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
Trying to hack something?
_________________________
The tart is out there

Top
#120917 - 2004-06-09 05:55 PM Re: Script to execute program on 20 subnets
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
there are several Sunbet UDF's in the UDF forum...


a quick search...

Subnet() - will tell if a given ip# is in a specified subnet.
IsInSubnet() - Checks if a given IP address is in a specified subnet
IsInIPRange() - Checks if IP address is part of a network (deprecated)
IsSubnetMask() - Validates subnet masks
CalcNetworkID() - Calculates the Network ID


Top
#120918 - 2004-06-09 05:57 PM Re: Script to execute program on 20 subnets
Jharper Offline
Fresh Scripter

Registered: 2003-07-29
Posts: 13
LOL! Nothing that exciting, My company has 20 offices spread out across the U.S. I'm looking to create some tasks that run periodically that do auditing and some other things at the same time.
Top
#120919 - 2004-06-09 07:27 PM Re: Script to execute program on 20 subnets
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
look for MOAN() in the UDF forum...

you can pass it a networkID and SNM and it will return an array of IPs
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#120920 - 2004-06-09 07:33 PM Re: Script to execute program on 20 subnets
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Do you realize how much ARP traffic you will generate by scanning that range?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#120921 - 2004-06-09 07:37 PM Re: Script to execute program on 20 subnets
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
there is also EnumDHCP() udf that will get the IPs from the server
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#120922 - 2004-06-09 07:41 PM Re: Script to execute program on 20 subnets
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
You could just nest a few FOR - NEXT loops.
Code:
Break on
$Pre="10.198."
$Oct3="10.","40.","50.","51.","54.","65.","70."
For each $Oct in $Oct3
For $Oct4=0 to 255
$ShellCMD="C:\KiXScripts\portchek "+$Pre+$Oct+$Oct4+" 36794"
Shell $ShellCMD
If @error
"No listener on port 36794 of "+$Pre+$Oct+$Oct4 ?
Else
"YIKES! LISTENER FOUND ON PORT 36794 OF "+$Pre+$Oct+$Oct4 ?
Beep
EndIf
Next
Next
"That's all folks!"?
Get $_

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#120923 - 2004-06-09 07:55 PM Re: Script to execute program on 20 subnets
Jharper Offline
Fresh Scripter

Registered: 2003-07-29
Posts: 13
Thanks Les, that's what I needed. I appreciate everyone's input. I knew the KiX masters could help me out!

Thanks again,
Jharper

Top
#120924 - 2004-06-09 08:02 PM Re: Script to execute program on 20 subnets
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
time to nitpick... oct 4 in a class c can't be 0 or 255, so the for/next should be modified

and 1 or 254 is usually the router...


Edited by Radimus (2004-06-09 08:04 PM)
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#120925 - 2004-06-09 08:04 PM Re: Script to execute program on 20 subnets
Jharper Offline
Fresh Scripter

Registered: 2003-07-29
Posts: 13
I've already changed it to 50 - 254. This is the served scope set for all subnets in my network.


Edited by Jharper (2004-06-09 08:06 PM)

Top
#120926 - 2004-06-09 08:38 PM Re: Script to execute program on 20 subnets
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Quote:

time to nitpick... oct 4 in a class c can't be 0 or 255, so the for/next should be modified

and 1 or 254 is usually the router...



Yeah, but in my case I have a class A
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#120927 - 2004-06-10 05:41 PM Re: Script to execute program on 20 subnets
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
just because i did the work... might as well post it

Needs BinaryIP() and BaseConverter()

Code:

Function GetSubnetIPs($subnet,$subnetmask)
dim $1,$0,$subnetid,$i,$convert
$1 = "11111111111111111111111111111111"
$0 = "00000000000000000000000000000000"
$subnetmask = substr(binaryip($subnetmask),1,instr(binaryip($subnetmask),0)-1)
$subnetid = substr(binaryip($subnet),1,len($subnetmask))
$subnet = substr(binaryip($subnet),len($subnetmask)+1)
dim $tarray[baseconverter(substr($1,1,len($subnet)),2,10)]
for $i = 0 to ubound($tarray)
$convert = baseconverter($i,10,2)
$ip = binaryip($subnetid + substr($0,1,len($subnet)-len($convert)) + $convert,1)
$tarray[$i] = $ip
next
$getsubnetips = $tarray
endfunction



EXAMPLE:
Code:

$ip = Getsubnetips("128.2.1.0","255.255.192.0")
? $ip[0]
? $ip[ubound($ip)]



Bryce

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Henriques) and 2516 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.068 seconds in which 0.03 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org