I want to create a batch or vbs file that will put together a url and executed. Part of that url needs to be the actual ip address of the machine. How I am able to get that IP address in a variable to include it on the script?
EDIT 1:
I found out that the command below will give me the IP Address, but still don't know how to get that value into a variable to use it in a script.
c:\> wmic NICCONFIG WHERE IPEnabled=true GET IPAddress /format:csv
Node,IPAddress
IP-0AFB,{10.25.5.2}
Here's some sample code I used in a previous script...
If you want to return the IP address into a variable, you could do the following:
This code is taken straight from the Scriptomatic v2.0 from Microsoft's TechNet Scriptcenter. Found here: http://technet.microsoft.com/en-us/scriptcenter/dd939957.aspx
Here is a way to extract the WMIC results into a variable in a cmd script:
Notice that since there may be multiple NICs, we have to loop through WMIC's output, which is accomplished by calling :SETVAR for each line of WMIC output (skipping the first one, though, and testing for any blank trailing lines. A variable is created for each enabled NIC found - the variables will be %NIC1%, %NIC2%, etc.
Line 12, starting with "echo NIC", can be removed once you have it working to your satisfaction.
You know, to make this REALLLLLY useful, I added
/node:%1
(to get IP of remote computer) Saves some legwork for system admins & network admins vs. ping or nslookup. I'm sure the other thing I will add is 'error-checking' so that, IF the system happens to not be available, the script can "log that info" - likeSystem %1 not available
- and then move on to grab the ip of the next system.Often, I make a 'bat' to 'call a bat' So, I would just create a batch file maybe like "getall.bat" below:
Then just run it like this:
getall > getall-log.txt 2>&1
(Above will pipe out all the info to a text file, including any errors encountered)
getall.bat
getnic.bat
Converted for IPv6
I know you asked for a VBS or Batch style script but I thought I would add a PowerShell snippet as well if you wanted to try that route or for anyone else looking at this question...
This will return all IP Addresses currently assigned to the machine.