IP Address Of A Particular Adapter

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
CyberCitizen
Automation Wizard
Posts: 724
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

IP Address Of A Particular Adapter

Post by CyberCitizen » Tue May 01, 2012 7:44 am

Hi Guys,

Really need some help, this has stumped me.

I am writing a script which is used to pull various into & save it to a network location.

That's all sorted.

What I need is a way to retrieve the IP addresses of particular network adapters eg LAN & WiFi.

This is what I have so far.

Code: Select all

//Gets IP Addresses
Let>RP_WAIT=1
Let>RP_WINDOWMODE=0
Run Program>cmd /c ipconfig | find "IP Address" > %TEMP_DIR%IPOutput.txt
//ReadFile>%TEMP_DIR%IPOutput.txt,IPAddResults
ReadLn>%TEMP_DIR%IPOutput.txt,1,WiFiResult
ReadLn>%TEMP_DIR%IPOutput.txt,2,LanResult
StringReplace>%LanResult%,        IP Address. . . . . . . . . . . . : ,,LanResult
StringReplace>%WiFiResult%,        IP Address. . . . . . . . . . . . : ,,WiFiResult
DeleteFile>%TEMP_DIR%IPOutput.txt
The problem I have is I need both the LAN result and the WiFi in seperate fields. I can get the IP of the primary connection, however every now & then (more often than not) the user has both the WiFi & LAN connected. I need both IP's into separate variables and also the correct ones, eg the script I have uses the adapter order, so depending on what Windows detected first can affect this.

Any help would be appreciated.
FIREFIGHTER

User avatar
CyberCitizen
Automation Wizard
Posts: 724
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Fri May 04, 2012 2:17 am

Guess No One Has A Clue, It Stumped Me In Getting The Adaptor IP Addresses.

I Have Another Was Of Doing It Now & That Is Via The IP Range.

But I Still Need Some Script Help.

Say I Get An IP Address Of 10.142.48.123

What I Need Is The Third Lot Of Numbers (48) I Need An If Statement That If The Third Lot Of Numbers = 1 Through To 120 It Does Something.

If If The IP Address Is 10.142.48.123
It Reads The 3rd Lot Of Numbers Eg 48

If That Falls Between 1 Through To 120 It Sets A Label To L5

That Way I Can Reference The Location Of The IP Based On The Floor It's On.

Please Help, Kind Of Need To Get It Out Today.
FIREFIGHTER

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Fri May 04, 2012 5:41 am

Hi CyberCitizen,

I think the following will do what you're asking for...

Code: Select all

//comment out one or the other to test both scenarios

//value to test the Yes scenario (third octet is between 1 and 120)
Let>ip_blob=a bunch of text10.142.48.123with the ip buried inside

//value to test the No scenario (third octet is NOT between 1 and 120)
//Let>ip_blob=a bunch of text10.142.122.123with the ip buried inside

Let>pattern=\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}
RegEx>pattern,ip_blob,0,matches,num,0

//matches_1 should now contain just the ip address
Let>ip_address=matches_1

//now let's extract just the third_octet from that ip_address
Let>pattern=(\d{1,3}).(\d{1,3}).(\d{1,3}).(\d{1,3})
RegEx>pattern,ip_address,0,matches,num,1,$3,third_octet

If>{(%third_octet% > 0) AND (%third_octet% < 121)}
  MDL>Yes the third octet of %ip_address% is %third_octet% which is between 1 and 120
Else
  MDL>No the third octet of %ip_address% is %third_octet% which is NOT between 1 and 120
EndIf
Take Care
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
CyberCitizen
Automation Wizard
Posts: 724
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Fri May 04, 2012 6:53 am

Thanks jpuziano,

I actually just finished the script, its alittle messy but it was going to get like that when I added all the IP ranges.

It seems to work so far for me, I am now hoping something with VB scripting could help.

I need to retrieve the machines serial number while under a user account. I have tried the old WMIC trick but that needs admin rights. There is a VBS script that works but I don't know how to incorporate it into my script.

This is the script that does it http://h41111.www4.hp.com/hps/carepack/ ... erial.html

If you know any other way or can provide assistance that would be great.
FIREFIGHTER

User avatar
CyberCitizen
Automation Wizard
Posts: 724
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Fri Jun 29, 2012 1:42 am

Worked it out with that script in case anyone else needed it.

Code: Select all

//Gets Machine Serial Number
Let>RP_WAIT=1
Let>RP_WINDOWMODE=0
Run Program>cmd /c cscript "serial_number.vbs" //nologo > %TEMP_DIR%SN.txt
ReadLn>%TEMP_DIR%SN.txt,1,SNResults
DeleteFile>%TEMP_DIR%SN.txt
If>SNResults=##EOF##
Let>SNResults=Not Available
Else
EndIf
FIREFIGHTER

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts