Grandmaster All American 10829 Posts user info edit post |
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.
Quote : | " set varip=192.168.1.100 set varip2=10.1.1.100
netsh int ip set address name = "Local Area Connection" source = static addr = %varip% mask = %varsm%
netsh int ip add address name = "Local Area Connection" source = static addr = %varip2% mask = %varsm% " |
1) Instead of manually declaring the variables is there any way to grab the current IP address from ifconfig (or netsh?) assign it to varip and then add the 4th octet to varip2?
2) If not, can the script remain as it is except varip=192.168.1.x and when ran it asks me to input x?
Thanks always, GRANDMASTA7/1/2010 11:16:05 AM |
FroshKiller All American 51911 Posts user info edit post |
What environment? 7/1/2010 11:20:36 AM |
Grandmaster All American 10829 Posts user info edit post |
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 |
FroshKiller All American 51911 Posts user info edit post |
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 |
Shaggy All American 17820 Posts user info edit post |
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 if next
you have to run it as an administrator on vista or 7 though.7/1/2010 12:27:52 PM |
Shaggy All American 17820 Posts user info edit post |
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.1
Then 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
and run that as administrator7/1/2010 12:32:13 PM |
FroshKiller All American 51911 Posts user info edit post |
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 |
Grandmaster All American 10829 Posts user info edit post |
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 |
FroshKiller All American 51911 Posts user info edit post |
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 |