Need a wise script
Can you help me write a wise script that can get an ipaddress of local machine.
0 Comments
[ + ] Show comments
Answers (2)
Please log in to answer
Posted by:
Chipster
17 years ago
I used this one recently for something we were deploying. I needed to get the local IP address and match it with a list to determine what remote server to connect to.
item: Set Variable
Variable=IPFILE
Value=%WIN%\Temp\ipconfig.txt
end
item: Execute Program
Pathname=%COMSPEC%
Command Line=/c for /f "tokens=1,2 delims=:" %%a in ('ipconfig ^| findstr /i "address"') do @echo %%b | find /i "10." > %IPFILE%
Flags=00001010
end
item: Check if File/Dir Exists
Pathname=%IPFILE%
Flags=00000100
end
item: Read/Update Text File
Variable=IPADDRESS
Pathname=%IPFILE%
end
item: Parse String
Source=%IPADDRESS%
Pattern=.
Variable1=IP0
Variable2=IP4
Flags=00000101
end
item: Parse String
Source=%IP0%
Pattern=.
Variable1=IP0
Variable2=IP3
Flags=00000101
end
item: Parse String
Source=%IP0%
Pattern=.
Variable1=IP0
Variable2=IP2
Flags=00000101
end
item: Parse String
Source=%IP0%
Pattern=.
Variable1=IP0
Variable2=IP1
Flags=00000101
end
item: Set Variable
Variable=IPADDRESS
Value=%IP1%.%IP2%.%IP3%.%IP4%
end
item: Set Variable
Variable=IPSTART
Value=%IP1%.%IP2%.%IP3%
end
item: End Block
end
There might be an easier way but it worked for me.
%COMSPEC% is the command interpreter location that I get earlier in my script.
it runs a command prompt, does an ipconfig and filters out only the address and then only addresses that start with 10. you could change this to reflect your prefix as well if not 10.x. This was done to filter out auto configured or static ips etc.
Then it parses it out into the each octet. the end result is that the variable %IPADDRESS% is the full dotted IP.
item: Set Variable
Variable=IPFILE
Value=%WIN%\Temp\ipconfig.txt
end
item: Execute Program
Pathname=%COMSPEC%
Command Line=/c for /f "tokens=1,2 delims=:" %%a in ('ipconfig ^| findstr /i "address"') do @echo %%b | find /i "10." > %IPFILE%
Flags=00001010
end
item: Check if File/Dir Exists
Pathname=%IPFILE%
Flags=00000100
end
item: Read/Update Text File
Variable=IPADDRESS
Pathname=%IPFILE%
end
item: Parse String
Source=%IPADDRESS%
Pattern=.
Variable1=IP0
Variable2=IP4
Flags=00000101
end
item: Parse String
Source=%IP0%
Pattern=.
Variable1=IP0
Variable2=IP3
Flags=00000101
end
item: Parse String
Source=%IP0%
Pattern=.
Variable1=IP0
Variable2=IP2
Flags=00000101
end
item: Parse String
Source=%IP0%
Pattern=.
Variable1=IP0
Variable2=IP1
Flags=00000101
end
item: Set Variable
Variable=IPADDRESS
Value=%IP1%.%IP2%.%IP3%.%IP4%
end
item: Set Variable
Variable=IPSTART
Value=%IP1%.%IP2%.%IP3%
end
item: End Block
end
There might be an easier way but it worked for me.
%COMSPEC% is the command interpreter location that I get earlier in my script.
it runs a command prompt, does an ipconfig and filters out only the address and then only addresses that start with 10. you could change this to reflect your prefix as well if not 10.x. This was done to filter out auto configured or static ips etc.
Then it parses it out into the each octet. the end result is that the variable %IPADDRESS% is the full dotted IP.
Posted by:
michaelnowell
17 years ago
This should do the trick. It pulls the IPAddress usign dll commands
Document Type: WSE
item: Global
Version=9.02
Flags=01000100
Languages=65 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Copy Default=1
Japanese Font Name=MS Gothic
Japanese Font Size=9
Start Gradient=0 0 255
End Gradient=0 0 0
Windows Flags=00000100000000000010110001001010
Message Font=MS Sans Serif
Font Size=8
Disk Filename=SETUP
Patch Flags=0000000000000001
Patch Threshold=85
Patch Memory=4000
MIF PDF Version=1.0
MIF SMS Version=2.0
FTP Cluster Size=20
Per-User Version ID=1
Dialogs Version=9
Crystal Format=10111100101100000010001001001001
Crystal Destination=00000000000000000000000000001011
WamDB Index=C:\Program Files\Wise Package Studio\
Step View=&Properties
Variable Name1=_INIT_WINDOW_
Variable Default1=HIDE
Variable Flags1=00001000
end
item: Remark
end
item: Get Environment Variable
Variable=COMPUTERNAME
Environment=ComputerName
end
remarked item: Display Message
Title=COMPUTERNAME
Text=Computername=%COMPUTERNAME%
end
item: Remark
end
item: Call DLL Function
Pathname=%SYS32%\KERNEL32.DLL
Function Name=LoadLibraryA
Argument List=41%SYS32%\WSOCK32.DLL
Return Variable=3HWSOCK32DLL
Flags=00100000
end
remarked item: Display Message
Title=HWSOCK32DLL
Text=%HWSOCK32DLL%
end
item: If/While Statement
Variable=HWSOCK32DLL
Value=0
end
remarked item: Display Message
Title=Get IP Addresses
Text=TCP/IP not properly installed!
Flags=00110000
end
item: Else Statement
end
item: Call DLL Function
Pathname=%SYS32%\WSOCK32.DLL
Function Name=WSAStartup
Argument List=110x0101
Argument List=q0VERSION
Argument List=±0VERSIONHIGH
Argument List=¹0@ÿDESCRIPTION
Argument List=¹0¡ SYSTEMSTATE
Argument List=±0MAXSOCKETS
Argument List=±0MAXUDPDG
Argument List=´0VENDORINFO
Return Variable=2RETURN
Flags=00100000
end
remarked item: Display Message
Title=RETURN
Text=%RETURN%
end
item: If/While Statement
Variable=RETURN
Value=0
Flags=00000001
end
remarked item: Display Message
Title=Get IP Addresses
Text=Error initializing Winsock layer!
Flags=00110000
end
item: Else Statement
end
item: Set Variable
Variable=MACHINE
Value=%COMPUTERNAME%
end
remarked item: Display Message
Title=MACHINE
Text=%MACHINE%
end
item: Set Variable
Variable=IPADDRESS
Value=unknown
end
item: Call DLL Function
Pathname=%SYS32%\WSOCK32.DLL
Function Name=gethostbyname
Argument List=40MACHINE
Return Variable=3HOSTENTPTR
Flags=00100000
end
remarked item: Display Message
Title=HOSTENTPTR (gethostbyname)
Text=%HOSTENTPTR%
end
item: If/While Statement
Variable=HOSTENTPTR
Value=0
Flags=00000001
end
item: Call DLL Function
Pathname=%SYS32%\KERNEL32.DLL
Function Name=RtlMoveMemory
Argument List=s0NAME_PTR
Argument List=³0ALIASES_PTR
Argument List=°0ADDRESS_TYPE
Argument List=°0ADDRESS_LENGTH
Argument List=³0IP_PTR_PTR
Argument List=30HOSTENTPTR
Argument List=3116
Return Variable=3
Flags=00100000
end
item: Remark
Text=Store the host's IP address in variable IPADDRESS:
end
item: Call DLL Function
Pathname=%SYS32%\KERNEL32.DLL
Function Name=RtlMoveMemory
Argument List=80IP_PTR
Argument List=30IP_PTR_PTR
Argument List=314
Return Variable=3
Flags=00100000
end
item: Call DLL Function
Pathname=%SYS32%\KERNEL32.DLL
Function Name=RtlMoveMemory
Argument List=80BINARY_IP
Argument List=30IP_PTR
Argument List=314
Return Variable=3
Flags=00100000
end
item: Call DLL Function
Pathname=%SYS32%\WSOCK32.DLL
Function Name=inet_ntoa
Argument List=30BINARY_IP
Return Variable=4IPADDRESS_PTR
Flags=00100000
end
remarked item: Display Message
Title=BINARY_IP
Text=%BINARY_IP%
end
remarked item: Display Message
Title=IPADDRESS_PTR
Text=%IPADDRESS_PTR%
end
item: Call DLL Function
Pathname=%SYS32%\KERNEL32.DLL
Function Name=lstrcpyA
Argument List=40IPADDRESS
Argument List=30IPADDRESS_PTR
Return Variable=3
Flags=00100000
end
item: End Block
end
item: Call DLL Function
Pathname=%SYS32%\WSOCK32.DLL
Function Name=WSACleanup
Return Variable=2RETURN
Flags=00100000
end
item: End Block
end
item: Remark
Text=Unload Winsock DLL
end
item: Call DLL Function
Pathname=%SYS32%\KERNEL32.DLL
Function Name=FreeLibrary
Argument List=30HWSOCK32DLL
Return Variable=3
Flags=00100000
end
item: End Block
end
item: Remark
end
item: Set Variable
Variable=IPADDRESS
Value=%IPADDRESS_PTR%
end
item: Display Message
Title=IPADDRESS
Text=The IP address of this machine is "%IPADDRESS%"
end
item: Remark
end
item: Remark
end
item: Remark
end
item: Remark
end
item: Remark
end
item: Remark
end
Document Type: WSE
item: Global
Version=9.02
Flags=01000100
Languages=65 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Copy Default=1
Japanese Font Name=MS Gothic
Japanese Font Size=9
Start Gradient=0 0 255
End Gradient=0 0 0
Windows Flags=00000100000000000010110001001010
Message Font=MS Sans Serif
Font Size=8
Disk Filename=SETUP
Patch Flags=0000000000000001
Patch Threshold=85
Patch Memory=4000
MIF PDF Version=1.0
MIF SMS Version=2.0
FTP Cluster Size=20
Per-User Version ID=1
Dialogs Version=9
Crystal Format=10111100101100000010001001001001
Crystal Destination=00000000000000000000000000001011
WamDB Index=C:\Program Files\Wise Package Studio\
Step View=&Properties
Variable Name1=_INIT_WINDOW_
Variable Default1=HIDE
Variable Flags1=00001000
end
item: Remark
end
item: Get Environment Variable
Variable=COMPUTERNAME
Environment=ComputerName
end
remarked item: Display Message
Title=COMPUTERNAME
Text=Computername=%COMPUTERNAME%
end
item: Remark
end
item: Call DLL Function
Pathname=%SYS32%\KERNEL32.DLL
Function Name=LoadLibraryA
Argument List=41%SYS32%\WSOCK32.DLL
Return Variable=3HWSOCK32DLL
Flags=00100000
end
remarked item: Display Message
Title=HWSOCK32DLL
Text=%HWSOCK32DLL%
end
item: If/While Statement
Variable=HWSOCK32DLL
Value=0
end
remarked item: Display Message
Title=Get IP Addresses
Text=TCP/IP not properly installed!
Flags=00110000
end
item: Else Statement
end
item: Call DLL Function
Pathname=%SYS32%\WSOCK32.DLL
Function Name=WSAStartup
Argument List=110x0101
Argument List=q0VERSION
Argument List=±0VERSIONHIGH
Argument List=¹0@ÿDESCRIPTION
Argument List=¹0¡ SYSTEMSTATE
Argument List=±0MAXSOCKETS
Argument List=±0MAXUDPDG
Argument List=´0VENDORINFO
Return Variable=2RETURN
Flags=00100000
end
remarked item: Display Message
Title=RETURN
Text=%RETURN%
end
item: If/While Statement
Variable=RETURN
Value=0
Flags=00000001
end
remarked item: Display Message
Title=Get IP Addresses
Text=Error initializing Winsock layer!
Flags=00110000
end
item: Else Statement
end
item: Set Variable
Variable=MACHINE
Value=%COMPUTERNAME%
end
remarked item: Display Message
Title=MACHINE
Text=%MACHINE%
end
item: Set Variable
Variable=IPADDRESS
Value=unknown
end
item: Call DLL Function
Pathname=%SYS32%\WSOCK32.DLL
Function Name=gethostbyname
Argument List=40MACHINE
Return Variable=3HOSTENTPTR
Flags=00100000
end
remarked item: Display Message
Title=HOSTENTPTR (gethostbyname)
Text=%HOSTENTPTR%
end
item: If/While Statement
Variable=HOSTENTPTR
Value=0
Flags=00000001
end
item: Call DLL Function
Pathname=%SYS32%\KERNEL32.DLL
Function Name=RtlMoveMemory
Argument List=s0NAME_PTR
Argument List=³0ALIASES_PTR
Argument List=°0ADDRESS_TYPE
Argument List=°0ADDRESS_LENGTH
Argument List=³0IP_PTR_PTR
Argument List=30HOSTENTPTR
Argument List=3116
Return Variable=3
Flags=00100000
end
item: Remark
Text=Store the host's IP address in variable IPADDRESS:
end
item: Call DLL Function
Pathname=%SYS32%\KERNEL32.DLL
Function Name=RtlMoveMemory
Argument List=80IP_PTR
Argument List=30IP_PTR_PTR
Argument List=314
Return Variable=3
Flags=00100000
end
item: Call DLL Function
Pathname=%SYS32%\KERNEL32.DLL
Function Name=RtlMoveMemory
Argument List=80BINARY_IP
Argument List=30IP_PTR
Argument List=314
Return Variable=3
Flags=00100000
end
item: Call DLL Function
Pathname=%SYS32%\WSOCK32.DLL
Function Name=inet_ntoa
Argument List=30BINARY_IP
Return Variable=4IPADDRESS_PTR
Flags=00100000
end
remarked item: Display Message
Title=BINARY_IP
Text=%BINARY_IP%
end
remarked item: Display Message
Title=IPADDRESS_PTR
Text=%IPADDRESS_PTR%
end
item: Call DLL Function
Pathname=%SYS32%\KERNEL32.DLL
Function Name=lstrcpyA
Argument List=40IPADDRESS
Argument List=30IPADDRESS_PTR
Return Variable=3
Flags=00100000
end
item: End Block
end
item: Call DLL Function
Pathname=%SYS32%\WSOCK32.DLL
Function Name=WSACleanup
Return Variable=2RETURN
Flags=00100000
end
item: End Block
end
item: Remark
Text=Unload Winsock DLL
end
item: Call DLL Function
Pathname=%SYS32%\KERNEL32.DLL
Function Name=FreeLibrary
Argument List=30HWSOCK32DLL
Return Variable=3
Flags=00100000
end
item: End Block
end
item: Remark
end
item: Set Variable
Variable=IPADDRESS
Value=%IPADDRESS_PTR%
end
item: Display Message
Title=IPADDRESS
Text=The IP address of this machine is "%IPADDRESS%"
end
item: Remark
end
item: Remark
end
item: Remark
end
item: Remark
end
item: Remark
end
item: Remark
end
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.