General Macro Scheduler discussion
Moderators: Dorian (MJT support), JRL
-
JRL
- Automation Wizard
- Posts: 3526
- Joined: Mon Jan 10, 2005 6:22 pm
- Location: Iowa
Post
by JRL » Mon Feb 07, 2011 10:43 pm
For years I've used DOS ipconfig to create a file to be parsed for the local ip address. Then along comes Win 7 (and probably Vista) and the ipconfig output changed. I set about to detect the version and parse per version but decided to stop and think about it first. Checked the forum, checked the web for a VBScript solution or a poll the Registry method. didn't find anything. Then it occured to me to test DOS tracert. And it works. As long as the "-4" option is used to force IPv4.
I'd like to find out if this is at all a universal solution. Can you test this and report back as to whether it passes and reports a good local IP address or fails and reports gibberish. And if it reports gibberish, can you identify the gibberish. Also tell the operating system(s) you tested on.
Thanks for your time,
Dick
Code: Select all
Let>RP_wait=1
Let>RP_windowmode=0
Run>cmd /c tracert -4 %computer_name% > %temp_dir%ipaddresscap.txt
ReadFile>%temp_dir%ipaddresscap.txt,data
Separate>data,],var
Separate>var_1,[,addr
DeleteFile>%temp_dir%ipaddresscap.txt
MDL>addr_2
-
jpuziano
- Automation Wizard
- Posts: 1085
- Joined: Sat Oct 30, 2004 12:00 am
Post
by jpuziano » Tue Feb 08, 2011 1:25 am
Hi JRL,
It reports a good local IP address on Windows 7 Professional.
-
JRL
- Automation Wizard
- Posts: 3526
- Joined: Mon Jan 10, 2005 6:22 pm
- Location: Iowa
Post
by JRL » Tue Feb 08, 2011 1:51 pm
Thanks jpuziano. I appreciate the feedback.
The "-4" tracert parameter is necessary for Win 7 and seems to be accepted and ignored by Win XP but causes a crash in Win 2000. So I added a test to determine whether the OS is greater than XP. Since XP does not need the parameter there's no need to use it.
Does this work or not work for you? Or do you know of a better way to acquire the local IP address? Let me know.
Thanks,
Dick
Code: Select all
Let>RP_WAIT=1
Let>RP_WINDOWmode=0
Separate>OS_VER,.,ver
If>ver_2>5
Run>cmd /c tracert -4 %computer_name% > %temp_dir%ipaddresscap.txt
Else
Run>cmd /c tracert %computer_name% > %temp_dir%ipaddresscap.txt
EndIf
ReadFile>%temp_dir%ipaddresscap.txt,data
Separate>data,],var
Separate>var_1,[,addr
DeleteFile>%temp_dir%ipaddresscap.txt
MDL>addr_2
-
adroege
- Automation Wizard
- Posts: 438
- Joined: Tue Dec 07, 2004 7:39 pm
Post
by adroege » Tue Feb 08, 2011 6:28 pm
This worked for me (popped up the message with the ip address)
MS version 12.0.8 OS=XP SP3
Code: Select all
//get local IP address
VBSTART
'On Error Resume Next
wbemFlagReturnImmediately = &h10
wbemFlagForwardOnly = &h20
Set objWMIService = GetObject("winmgmts:\\" & "." & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT IPAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
strIPAddress = Join(objItem.IPAddress, ",")
WScript.Echo "IPAddress: " & strIPAddress
Next
VBEND
-
JRL
- Automation Wizard
- Posts: 3526
- Joined: Mon Jan 10, 2005 6:22 pm
- Location: Iowa
Post
by JRL » Tue Feb 08, 2011 6:38 pm
Thanks adroege, I'll see if I can adapt the code to VBEval so I can get the address to a variable.
-
jpuziano
- Automation Wizard
- Posts: 1085
- Joined: Sat Oct 30, 2004 12:00 am
Post
by jpuziano » Tue Feb 08, 2011 6:44 pm
JRL wrote:Thanks jpuziano. I appreciate the feedback.
The "-4" tracert parameter is necessary for Win 7 and seems to be accepted and ignored by Win XP but causes a crash in Win 2000. So I added a test to determine whether the OS is greater than XP. Since XP does not need the parameter there's no need to use it.
Does this work or not work for you? Or do you know of a better way to acquire the local IP address? Let me know.
Thanks,
Dick
Code: Select all
Let>RP_WAIT=1
Let>RP_WINDOWmode=0
Separate>OS_VER,.,ver
If>ver_2>5
Run>cmd /c tracert -4 %computer_name% > %temp_dir%ipaddresscap.txt
Else
Run>cmd /c tracert %computer_name% > %temp_dir%ipaddresscap.txt
EndIf
ReadFile>%temp_dir%ipaddresscap.txt,data
Separate>data,],var
Separate>var_1,[,addr
DeleteFile>%temp_dir%ipaddresscap.txt
MDL>addr_2
Yes, that code worked fine for me and displayed my local ip address.
Tested on: XP SP3 using MS 12.1.4
Take care