Sup TT,I know there are proably a million easier ways to do what I'm about to ask if I actually knew any programming language -- perhaps even if I had a "For Dummies" book as reference but right now I'm just wanting to use this batch file I found online. I'll save your time by only using snippets and we'll assume my other called variables are added.-----Impatient People Start Reading Here-----Scenario: This computer has an IP of 192.168.1.100 by way of DHCP. I want to change the adapter to use that same IP but as a static so that I can also add 10.1.1.100.
7/1/2010 11:16:05 AM
What environment?
7/1/2010 11:20:36 AM
at the risk of sounding like an idiot or eating troll bait, isn't the environment implied by .bat?--I'm basically just chaining DOS commands here on XP/Vista boxes. I've edited/stolen some .vbs scripts in the past so I could possibly bullshit my way through something there if needed but this is for about 5 remote computers with a window of opportunity I noticed for future situations.[Edited on July 1, 2010 at 12:03 PM. Reason : .]
7/1/2010 11:58:51 AM
It implies about as much as .PCX or .1ST or whatever the hell other file extension you want to put out there. I can stick .BAT on the end of a BASH script written for a Debian workstation and execute it pretty as you please.You can use a combination of ipconfig, find, and the substring operator (%) to accomplish this. You can Google it up for yourself, or maybe I'll have a few minutes to hash it out myself.
7/1/2010 12:21:32 PM
heres some vb
strComputer="compname"strIPToChange="192.168.1"strIPToAdd="10.1.1"Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")Set colItems = objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where ipenabled='true'")For Each objItem in colItems strIP= objItem.ipaddress(0) if inStr(strIP,strIPToChange) > 0 then strLastOctet= Mid(strIP,InStrRev(strIP,".")+1,3) strAddIP=strIPToAdd&"."&strLastOctet arrIPAddresses=Array(strIP,strAddIP) arrSubnetMasks=Array("255.255.255.0","255.255.255.0") errStatic = objItem.EnableStatic(arrIPAddresses,arrSubnetMasks) wscript.echo(errStatic) end ifnext
7/1/2010 12:27:52 PM
that looks at all the network adapters that have IP turned on and have a current address matching strIPToChange, in your case 192.168.1. Then it finds the last octet and tacks it on to strIPToAdd, in your case 10.1.1Then it sets the adapter to static and adds both IP addresses with subnetmasks 255.255.255.0. I dont think theres a simple way to run a .vbs as admin so create a batch file thats
wscript fullpath\to\the\addip.vbs
7/1/2010 12:32:13 PM
Here, this should reliably parse the full IP address out of ipconfig and set the environment variable ipaddress to the system's current IP address:for /f "delims=" %a in ('ipconfig ^| find "IP Address"') do @set tempipaddress=%a set ipaddress = %tempipaddress:~44%You should be able to figure out the rest.
7/1/2010 12:44:00 PM
My apologies Frosh, 'ifconfig' was a crucial typo on my part. Thanks for the input guiz, once I get back from lunch this shit is on like donkey kong.
7/1/2010 1:36:18 PM
Ah yeah, "ifconfig" is another reason I asked about the environment. I was like, "Oh, okay, probably Windows, so...wait."
7/1/2010 1:39:53 PM