#61430 - 2001-12-18 02:37 AM
How do you obtain "active" IPADDRESS0,1,2 etc..
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11634
Loc: Space
|
I'm looking for a way or method to get back the IP address of the "active" Network connection.Sample:
code:
SELECT CASE (SUBSTR(@IPADDRESS0,1,11)) = "177. 21.128" $logsrv = "SERVER5" $spserver = "SERVER4" CASE (SUBSTR(@IPADDRESS0,1,7)) = "132.105" $logsrv = "SERVER2" $spserver = "SERVER2" CASE (SUBSTR(@IPADDRESS0,1,7)) = "155. 6" $logsrv = "SERVER3" $spserver = "SERVER3" CASE 1 $logsrv = "SERVER1" $spserver = "unknown" ENDSELECT
This will get me back the IP Address of the 0 interface but not the 1, 2, 3 etc... Some systems may have other PCMCIA cards, or AOL, Dialup connections, or a dual nic card. How can I detemine which card is active and get the IP address of that one and not just refer to the 0 one. On some systems you get back the built in default IP for Windows 2000 169.254.101.152 
|
|
Top
|
|
|
|
#61431 - 2001-12-18 05:39 PM
Re: How do you obtain "active" IPADDRESS0,1,2 etc..
|
bleonard
Seasoned Scripter
   
Registered: 2001-01-19
Posts: 581
Loc: Chicago, IL
|
NTDOC - Thinking off the top of my head, you could:+ Win2K-class, run NBTSTAT -n to a file and use Readline for the value appended to 'Node IpAddress' in the 3rd line of the file. + WinNT-class, obtain IP address(es) using @IPADDRESSx, run NBTSTAT -A (ipaddress) to file, and check for 'Host not found' in the 1st line of the file. Neither process is especially fast for login script usage, but shoud provide what you are looking for using existing NT tools with minimal scripting on your part. Bill [ 18 December 2001: Message edited by: bleonard ]
|
|
Top
|
|
|
|
#61432 - 2001-12-18 06:44 PM
Re: How do you obtain "active" IPADDRESS0,1,2 etc..
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
look at this and see if it is helpful. It only works under w2k
code:
; find ipconfig info (for up to 10 adapters) $interfaces="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces" $nic=0 dim $ipaddrs[9] dim $gateway[9] dim $subnetm[9] dim $namesvr[9] :nicloop $niccard=enumkey("$interfaces",$nic) if @error=0 $Isdhcp=readvalue("$interfaces\$niccard","EnableDHCP") if $Isdhcp="1" $adddhcp="Dhcp" else $adddhcp="" endif $ipaddrs[nic]=readvalue("$interfaces\$niccard","$adddhcp"+"IPAddress") $gateway[nic]=readvalue("$interfaces\$niccard","$adddhcp"+"DefaultGateway") $subnetm[nic]=readvalue("$interfaces\$niccard","$adddhcp"+"SubnetMask") $namesvr[nic]=readvalue("$interfaces\$niccard","$adddhcp"+"NameServer") $gateway[nic]=left($gateway[nic],len($gateway[nic])-1) if $gateway[nic] > "0.0.0.0" $mygw=$gateway[nic] endif $nic=$nic+1 goto nicloop endif
|
|
Top
|
|
|
|
#61435 - 2001-12-19 08:40 AM
Re: How do you obtain "active" IPADDRESS0,1,2 etc..
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11634
Loc: Space
|
Here is what I get back from Radimus's code.code:
; find ipconfig info (for up to 10 adapters) $interfaces="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces" $nic=0 dim $ipaddrs[9] dim $gateway[9] dim $subnetm[9] dim $namesvr[9] :nicloop $niccard=enumkey("$interfaces",$nic) if @error=0 $Isdhcp=readvalue("$interfaces\$niccard","EnableDHCP") if $Isdhcp="1" $adddhcp="Dhcp" else $adddhcp="" endif $ipaddrs[$nic]=readvalue("$interfaces\$niccard","$adddhcp"+"IPAddress") $gateway[$nic]=readvalue("$interfaces\$niccard","$adddhcp"+"DefaultGateway") $subnetm[$nic]=readvalue("$interfaces\$niccard","$adddhcp"+"SubnetMask") $namesvr[$nic]=readvalue("$interfaces\$niccard","$adddhcp"+"NameServer") $gateway[$nic]=left($gateway[nic],len($gateway[$nic])-1) if $gateway[$nic] > "0.0.0.0" $mygw=$gateway[$nic] endif $nic=$nic+1 goto nicloop endif ? $nic ? $mygw ? $gateway[$nic]
code:
C:\SCRIPTS\KiX2001>kix32 checknic.kix4
Maybe I'm doing something wrong... I only get back the number 4 on screen. I have 4 Nic Adapters... As shown by the WMI Code..
code:
System Manufacturer is = System Manufacturer System Model is = System Name System Serial Number is = SYS-1234567890 System BIOS Version is = ASUS CUSL2 ACPI BIOS Revision 1009 System BIOS Date is = Award Medallion BIOS v6.0 CPU Speed is = 938 Mhz System Memory = 255 MB Dimm Size = 128 MB Dimm Size = 128 MB Video Card is = All-in-Wonder RADEON Video Res is = 1600 x 1200 x 4294967296 colors Modem is = Network Card is = Cisco Systems VPN Adapter Network Card is = Cisco Systems VPN Adapter Network Card is = Cisco Systems VPN Adapter Network Card is = WAN Network Driver Network Card is = Linksys LNE100TX(v5) Fast Ethernet Adapter
Please point me in the right direction here Radimus...
|
|
Top
|
|
|
|
#61436 - 2001-12-19 03:04 PM
Re: How do you obtain "active" IPADDRESS0,1,2 etc..
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
You guys are picky... wanting code to actually work It also seems to work under XP... (of course 2k and xp are about the same thing...) code:
; find ipconfig info (for up to 10 adapters) $interfaces="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces" $nic=0 dim $ipaddrs[9] dim $gateway[9] dim $subnetm[9] dim $namesvr[9] :nicloop $niccard=enumkey("$interfaces",$nic) if @error=0 $Isdhcp=readvalue("$interfaces\$niccard","EnableDHCP") if $Isdhcp="1" $adddhcp="Dhcp" else $adddhcp="" endif $ipaddrs[$nic]=readvalue("$interfaces\$niccard","$adddhcp"+"IPAddress") $gateway[$nic]=readvalue("$interfaces\$niccard","$adddhcp"+"DefaultGateway") $subnetm[$nic]=readvalue("$interfaces\$niccard","$adddhcp"+"SubnetMask") $namesvr[$nic]=readvalue("$interfaces\$niccard","$adddhcp"+"NameServer") ; trim off pipe char from end of reg_multi $ipaddrs[$nic]=left($ipaddrs[$nic],len($ipaddrs[$nic])-1) $gateway[$nic]=left($gateway[$nic],len($gateway[$nic])-1) $subnetm[$nic]=left($subnetm[$nic],len($subnetm[$nic])-1) if $gateway[$nic] > "0.0.0.0" $mygw=$gateway[$nic]+"|"+$mygw ? "$adddhcp NIC number $nic" ? "IP :"$ipaddrs[$nic] ? "GW :"$gateway[$nic] ? "SM :"$subnetm[$nic] ? "NS :"$namesvr[$nic] endif $nic=val($nic)+1 goto nicloop endif $mygw=left($mygw,len($mygw)-1) ? "My Gateways are: "$mygw
output for me is:
code:
NIC number 1 IP :192.168.110.12 GW :192.168.110.1 SM :255.255.255.0 NS :65.32.2.130,65.32.1.70 My Gateways are: 192.168.110.1
[ 19 December 2001: Message edited by: Radimus ]
|
|
Top
|
|
|
|
#61439 - 2001-12-19 05:51 PM
Re: How do you obtain "active" IPADDRESS0,1,2 etc..
|
bleonard
Seasoned Scripter
   
Registered: 2001-01-19
Posts: 581
Loc: Chicago, IL
|
NTDOC and Radimus - Poking some more in the Win2k registry and my login script I've some more things that may be useful.1. Check key 'HKLM\Software\MS\Windows NT\CV\NetworkCards\(enum key)' ($WinKey). This will provide descriptive name of NIC that is displayed under LAN connection. If multiple NIC cards installed on the system they will be listed here. Most importantly, Will also provide the 32-character alphanumeric string name used elsewhere to identify the NIC under value '$WinKey, ServiceName' ($Nic). 2. You can also check key 'HKLM\System\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}' ($ClassKey). This key contains more NIC details. Specifically, you would want to check '$ClassKey\(enum subkey), NetCfgInstanceId' ($IPKey) for value that matches $Nic found in step 1. Then you could check '$IPKey\Linkage, UpperBind' for value 'Tcpip' to reconfirm this device is using the Tcpip protocol and is a valid NIC selection.
3. Can also examine key 'HKLM\System\CCS\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\$Nic, Name' to confirm the connection type. 4. Check key 'HKLM\System\CCS\Services\$Nic\Parameters\Tcpip'. This will display some of the IP configuration info stored in other reg keys referenced below in point 7. 5. Check 'HKLM\System\CCS\Services\RemoteAccess\Interfaces\(enum key), InterfaceName'. If value is = $Nic you have a NIC. Other values I know of are loopback, Internal. 6. Check key 'HKLM\System\CCS\Services\Tcpip\Linkage, Bind' to track the adapters bound to TCPIP protocol. Value under 'HKLM\System\CCS\Services\Tcpip\Linkage, Route' will likely define the NIC that is live on the network, which was NTDOC's original goal. The entries here are REG_MULTI_SZ, so I've yet to test the values returned with KiX 3.63. 7. Check key 'HKLM\System\CCS\Services\Tcpip\Parameters\Interfaces\$Nic'. As noted by Radimus, this contains the most detailed info of the IP configuration of the NIC. It appears 'HKLM\System\CCS\Services\Tcpip\Parameters\Interfaces\' will list IP-aware devices beyond specifically the installed Ethernet adapters. Therefore, use values from 1 above to narrow the keys to check. As for WinNT systems, check 'HKLM\System\CCS\NetBT\Adapters' to obtain NIC value ($Nic). Next, check key 'HKLM\System\CCS\Services\$Nic, Start'. This value will let you know specifically if the NIC is started when the system is booted. I believe a value of '3' indicates this is the case, though I am not positive of this value just yet. This will help for systems with multiple NIC's which are not run simultaneously. Hope this info is useful. Bill
|
|
Top
|
|
|
|
#61443 - 2001-12-19 11:45 PM
Re: How do you obtain "active" IPADDRESS0,1,2 etc..
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
try this:code:
$netcardkey="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards" $servicekey="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services" $Index1 = 0 :Loop1 $WinKey = ENUMKEY("$netcardkey", $Index1) If @ERROR = 0 ? "Card found: HKLM\S\M\WNT\CV\NetworkCards\$winkey" $nicID=readvalue("$netcardkey\$winkey","Servicename") $nicCN=readvalue("$netcardkey\$winkey","Description") if existkey("$servicekey\$nicID")=0 $ip=readvalue("$servicekey\$nicID\parameters\tcpip","IPAddress") $sm=readvalue("$servicekey\$nicID\parameters\tcpip","SubnetMask") $gw=readvalue("$servicekey\$nicID\parameters\tcpip","DefaultGateway") $ed=readvalue("$servicekey\$nicID\parameters\tcpip","EnableDHCP") ? $nicCN if $ed="0" ? "Static" else ? "DHCP" endif ? "IPAddress :"$ip ? "SubnetMask :"$sm ? "DefaultGateway :"$gw ? endif $Index1 = $Index1 + 1 goto Loop1 Endif
[ 20 December 2001: Message edited by: Radimus ] [ 20 December 2001: Message edited by: Radimus ]
|
|
Top
|
|
|
|
#61447 - 2001-12-27 02:37 PM
Re: How do you obtain "active" IPADDRESS0,1,2 etc..
|
Anonymous
Anonymous
Unregistered
|
Maybe using enumipinfo will make it a lot easier? When I read many threads it seems that not many people knows this function exist but is really worth to use it.
|
|
Top
|
|
|
|
#61449 - 2001-12-27 07:31 PM
Re: How do you obtain "active" IPADDRESS0,1,2 etc..
|
Anonymous
Anonymous
Unregistered
|
and for W9x machines.
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 384 anonymous users online.
|
|
|