AlbinoRaven Posted November 15, 2005 Share Posted November 15, 2005 Basically the following scripts ping a range of specified IP addresses which is then dropped into a txt file, another script picks the "available" IP address from the txt file and performs a netsh with the IP address variable and then assigns it to the NIC.What I'm having trouble with is the first script writes all of the IP's into the txt file, so there are a couple of hundred IP's in the list rather than the first available one.Second issue is the netsh command doesn't seem to want to assign the ip address. makes me sad.Anyhoo, I have the entire thing running as an "installation" item with the RunOnceEx.cmd during an unattended setup. Next to computer name assignment, the ip addressing is one pain of many in deploying 50 servers without touching anything but my coffee.Cheers!AlbinoOr if someone has a better way with VB I would seriously owe you a pint or a grande latte.--------------------------------------------------IPGrep1.cmd - releases the DHCP address====start here====@echo offipconfig /releaseexit====end here====IPGrep2.cmd - the entire thing must be pasted as one line! ====start here====@echo offfor /l %%a in (200,1,254) do (ping -n 1 -w 200 192.168.1.%%a |find "unreachable" && echo 192.168.1.%%a>>ipaddress.txt) ====end here====ipaddress.txt====start here====<pinged ip addresses that are unreachable>====end here====IPGrep3.cmd====start here====for /f %%i in (ipaddress.txt) do netsh interface ip set address name="Local Area Connection"&netsh interface ip set address local static %%i 255.255.255.0 192.168.1.1 ====end here==== Link to comment Share on other sites More sharing options...
cluberti Posted November 15, 2005 Share Posted November 15, 2005 1. Create a folder on C: called Iprange (or whatever, just modify the script if you use a different folder)2. Create a file in the iprange folder called source.txt3. On the first line of the source.txt file, place the IP range you'd like to scan, like so: 192.168.0.Run the following script:'*** Begin Script ***on error resume nextFunction Pingable(strHost)Dim objExec, objREset objshell = wscript.createobject("wscript.shell")blnPingable = "False" 'assume failureSet objExec = objShell.Exec("cmd /C ping -a -n 2 " & strHost)string1 = objExec.StdOut.ReadAllif instr(1,string1,"TTL=",1) >0 thenPingable = Trueelse pingable =false end ifif pingable =True thenChaine = "Pinging " Chaine2 = "[" ValueSearch = InStr(1,string1,Chaine,1) ValueSearch2 = InStr(valuesearch,string1,Chaine2,1) If ValueSearch>=1 and ValueSearch2>1 Then y= mid(string1,ValueSearch,(ValueSearch2-ValueSearch)) elsepingable="false"End If pingable = replace(y,"Pinging ","")pingable = replace(pingable," ","") if pingable =false or pingable="" then pingable ="False" end ifend ifSet objExec = NothingSet objRE = NothingEnd FunctionSet iFSO = CreateObject("Scripting.FilesyStemObject")Set oFSO = CreateObject("Scripting.FilesyStemObject")InputFile ="c:\IpRange\Source.txt"Outputfile="c:\IpRange\IpRangeLog.txt"Set ofile = ofso.createTextFile(OutputFile, True)Set ifile = iFSO.OpenTextFile(inputfile) Do until ifile.AtEndOfLineip = ifile.ReadLineofile.writeline "*************************************************"ofile.writeline "Scan network for ip range : " & ip & " Started"ofile.writeline now()x=ipFor i = 1 to 254x= x + cstr(i)servername = pingable(x)if servername<>"False" thenofile.writeline "________________________________________________"ofile.writeline "Machine= " & servername & ": IP Address= " & xofile.writeline "________________________________________________"elseofile.writeline "machine:" & x & " Not Pingable"end ifx=ipnextofile.writeline "Scan network for ip range : " & ip &" COmpleted"ofile.writeline now()ofile.writeline "*************************************************"loop'*** EOF ***This will dump all output to a file in the Iprange folder called IpRangeLog.txt. Do whatever you want with that data . Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now