#154781 - 2006-01-09 08:04 AM
RFC - GetIPOptions()
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4549
Loc: USA
|
I'm writing this to compliment SetIPOptions() and to address a request from this thread.
It should be able to accept any valid property from Win32_NetworkAdapterConfiguration class, including a few I created (ie StaticIP). Below are a few of the ones I targeted and tested. The function should always return a string.
I could really use someone to try out: 1. A PC with multiple NICs 2. Test it on a remote PC
Suggestions, Comments?
GetIPOptions() EnumNetworkConnections()
|
Top
|
|
|
|
#154785 - 2006-01-09 10:36 PM
Re: RFC - GetIPOptions()
|
Mart
KiX Supporter
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
|
Ok did some messing around at my home comp.
It has 2 "normal" NIC's, one wireless NIC, a Bluetooth thingy and a 1394 connection. When the BT connection is enabled it gives all 0's as the IP, SN, Def GW, etc.... When the BT connection is disabled it takes the IP's from the first connected NIC (wireless in my case). Is it possible to add the connection name to the output (Local Area Connection, Local Area Connection 2, etc…)? At the first line maybe?
Here is the output.
Quote:
Static Address: False DHCP Enabled: True IPaddress/SM: 192.168.2.100,255.255.255.0 IPaddress0/SM: 192.168.2.100,255.255.255.0 IPaddress1/SM: IPaddress2/SM: IPaddress3/SM: DefaultGW: 192.168.2.1 DNS Servers: 192.168.1.1,62.58.50.6 WINS Servers: DNSSuffix: DNS Search Order: DHCP Server: 192.168.2.1 DHCP Lease Obtained: 20060109201156.000000+060 DHCP Lease Expires: 20060119201156.000000+060
Will check against a remote comp and the teamed stuff @work on Wednesday.
[edit] D#mn. Should pay more attention to what I'm doing. Just logged off our terminal server and clicked reboot in stead off logoff More proof that men can't do two things at the same time. Working from home and kixing. [/edit]
Edited by Mart (2006-01-09 10:38 PM)
_________________________
Mart
- Chuck Norris once sold ebay to ebay on ebay.
|
Top
|
|
|
|
#154786 - 2006-01-10 12:05 AM
Re: RFC - GetIPOptions()
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
Loc: CA
|
Just trying to give folks at work a fresh start
|
Top
|
|
|
|
#154791 - 2006-01-11 04:50 PM
Re: RFC - GetIPOptions()
|
Mart
KiX Supporter
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
|
As promised. Did a test against a remote pc with two teamed Intel 10/100/1000 nics. MAC of the team is shown as expected.
Quote:
Static Address: True DHCP Enabled: False IPaddress/SM: 192.168.1.4,255.255.255.0 IPaddress0/SM: 192.168.1.4,255.255.255.0 IPaddress1/SM: IPaddress2/SM: IPaddress3/SM: DefaultGW: 192.168.1.8 DNS Servers: 192.168.1.1 WINS Servers: 127.0.0.0,127.0.0.0 DNSSuffix: DNS Search Order: DHCP Server: 192.168.1.1 DHCP Lease Obtained: DHCP Lease Expires: Mac Address: 00:02:B3:BE:2F:DF
Just specifying a value for $remotepc gives an error about undefined variable cause explicit is on and $remotepc is not dimmed I guess.
Edited by Mart (2006-01-11 04:52 PM)
|
Top
|
|
|
|
#154794 - 2006-01-27 04:07 PM
Re: RFC - GetIPOptions()
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4549
Loc: USA
|
Okay... I might actually have some time this weekend to mess with this.
Mart would you mind running the following code on the box where you had multiple adapters, and post the results?
Code:
Break On $strComputer = "." $objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2") $colItems = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration",,48) For each $objItem in $colItems "ArpAlwaysSourceRoute: " + $objItem.ArpAlwaysSourceRoute ? "ArpUseEtherSNAP: " + $objItem.ArpUseEtherSNAP ? "Caption: " + $objItem.Caption ? "DatabasePath: " + $objItem.DatabasePath ? "DeadGWDetectEnabled: " + $objItem.DeadGWDetectEnabled ? For each $Item in $objItem.DefaultIPGateway "*DefaultIPGateway: " + $Item ? Next "DefaultTOS: " + $objItem.DefaultTOS ? "DefaultTTL: " + $objItem.DefaultTTL ? "Description: " + $objItem.Description ? "DHCPEnabled: " + $objItem.DHCPEnabled ? "DHCPLeaseExpires: " + $objItem.DHCPLeaseExpires ? "DHCPLeaseObtained: " + $objItem.DHCPLeaseObtained ? "DHCPServer: " + $objItem.DHCPServer ? "DNSDomain: " + $objItem.DNSDomain ? For each $Item in $objItem.DNSDomainSuffixSearchOrder "*DNSDomainSuffixSearchOrder: " + $Item ? Next "DNSEnabledForWINSResolution: " + $objItem.DNSEnabledForWINSResolution ? "DNSHostName: " + $objItem.DNSHostName ? For each $Item in $objItem.DNSServerSearchOrder "*DNSServerSearchOrder: " + $Item ? Next "DomainDNSRegistrationEnabled: " + $objItem.DomainDNSRegistrationEnabled ? "ForwardBufferMemory: " + $objItem.ForwardBufferMemory ? "FullDNSRegistrationEnabled: " + $objItem.FullDNSRegistrationEnabled ? For each $Item in $objItem.GatewayCostMetric "*GatewayCostMetric: " + $Item ? Next "IGMPLevel: " + $objItem.IGMPLevel ? "Index: " + $objItem.Index ? For each $Item in $objItem.IPAddress "*IPAddress: " + $Item ? Next "IPConnectionMetric: " + $objItem.IPConnectionMetric ? "IPEnabled: " + $objItem.IPEnabled ? "IPFilterSecurityEnabled: " + $objItem.IPFilterSecurityEnabled ? "IPPortSecurityEnabled: " + $objItem.IPPortSecurityEnabled ? For each $Item in $objItem.IPSecPermitIPProtocols "*IPSecPermitIPProtocols: " + $Item ? Next For each $Item in $objItem.IPSecPermitTCPPorts "*IPSecPermitTCPPorts: " + $Item ? Next For each $Item in $objItem.IPSecPermitUDPPorts "*IPSecPermitUDPPorts: " + $Item ? Next For each $Item in $objItem.IPSubnet "*IPSubnet: " + $Item ? Next "IPUseZeroBroadcast: " + $objItem.IPUseZeroBroadcast ? "IPXAddress: " + $objItem.IPXAddress ? "IPXEnabled: " + $objItem.IPXEnabled ? "IPXFrameType: " + $objItem.IPXFrameType ? "IPXMediaType: " + $objItem.IPXMediaType ? "IPXNetworkNumber: " + $objItem.IPXNetworkNumber ? "IPXVirtualNetNumber: " + $objItem.IPXVirtualNetNumber ? "KeepAliveInterval: " + $objItem.KeepAliveInterval ? "KeepAliveTime: " + $objItem.KeepAliveTime ? "MACAddress: " + $objItem.MACAddress ? "MTU: " + $objItem.MTU ? "NumForwardPackets: " + $objItem.NumForwardPackets ? "PMTUBHDetectEnabled: " + $objItem.PMTUBHDetectEnabled ? "PMTUDiscoveryEnabled: " + $objItem.PMTUDiscoveryEnabled ? "ServiceName: " + $objItem.ServiceName ? "SettingID: " + $objItem.SettingID ? "TcpipNetbiosOptions: " + $objItem.TcpipNetbiosOptions ? "TcpMaxConnectRetransmissions: " + $objItem.TcpMaxConnectRetransmissions ? "TcpMaxDataRetransmissions: " + $objItem.TcpMaxDataRetransmissions ? "TcpNumConnections: " + $objItem.TcpNumConnections ? "TcpUseRFC1122UrgentPointer: " + $objItem.TcpUseRFC1122UrgentPointer ? "TcpWindowSize: " + $objItem.TcpWindowSize ? "WINSEnableLMHostsLookup: " + $objItem.WINSEnableLMHostsLookup ? "WINSHostLookupFile: " + $objItem.WINSHostLookupFile ? "WINSPrimaryServer: " + $objItem.WINSPrimaryServer ? "WINSScopeID: " + $objItem.WINSScopeID ? "WINSSecondaryServer: " + $objItem.WINSSecondaryServer ? ? Next
|
Top
|
|
|
|
#154798 - 2006-03-08 11:56 PM
Re: RFC - GetIPOptions()
|
Gargoyle
MM club member
Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
|
Ok, I worked with this in regards to this post http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=158386&an=0&page=0#158386 and used this code
Code:
Break On $=setoption("Wrapateol","on") $=setoption("Explicit","on") $=setoption("NoVarsinstrings","on") $=setoption("NoMacrosinstrings","on") dim $Server[],$ Open (1,"C:\DNS_Log.TXT",5) $Server = ;had 41 servers listed here For Each $ in $Server
;? " Static Address: " + getipoptions("StaticIP") ;? " DHCP Enabled: " + getipoptions("DHCPEnabled") ;? " IPaddress/SM: " + getipoptions("IPAddress") ;? " IPaddress0/SM: " + getipoptions("IPAddress0") ;? " IPaddress1/SM: " + getipoptions("IPAddress1") ;? " IPaddress2/SM: " + getipoptions("IPAddress2") ;? " IPaddress3/SM: " + getipoptions("IPAddress3") ;? " DefaultGW: " + getipoptions("DefaultGW") Writeline(1," Server: "+$+@CRLF) Writeline(1," DNS Servers: " + getipoptions("DNSServers",$)+@CRLF) ;? " WINS Servers: " + getipoptions("WINSServers") ;? " DNSSuffix: " + getipoptions("DNSDomain") ;? " DNS Search Order: " + getipoptions("DNSDomainSuffixSearchOrder") ;? " DHCP Server: " + getipoptions("DHCPServer") ;? "DHCP Lease Obtained: " + getipoptions("DHCPLeaseObtained") ;? " DHCP Lease Expires: " + getipoptions("DHCPLeaseExpires") ;? " Mac Address: " + getipoptions("Macaddress") Next
Close(1)
function GetIPOptions($Setting,optional $remotepc, optional $macaddress) dim $objWMIService, $colitems, $objnetadapter,$targetadapter,$,$allnics,$counter,$Mask,$SN, $IP, $IPAddress,$toggle if $remotepc="" $remotepc="." endif if $macaddress="" $allnics=1 endif $objWMIService = GetObject("winmgmts:\\" + $remotepc + "\root\cimv2") if @error exit @error endif $colItems = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=-1") For Each $objNetAdapter In $colItems if $macaddress=$objNetAdapter.macaddress or $allnics select case instr($setting,"IPAddress")>0 if right($setting,1)="s" or val(right($setting,1))>3 or len($setting)>10 $targetadapter=0 else $targetadapter=right($setting,1) endif $counter=0 for each $IP in $objNetAdapter.IPAddress if "" + $counter=$targetadapter $IPAddress=$IP endif $counter=$counter+1 next $counter=0 for each $SN in $objNetAdapter.IPSubnet if "" + $counter=$targetadapter $Mask=$SN endif $counter=$counter+1 next $GetIPOptions=$IPAddress if $mask $GetIPOptions=$GetIPOptions + "," + $Mask endif case $setting="WINSServers" $GetIPOptions=$objNetAdapter.WINSPrimaryServer if $objNetAdapter.WINSSecondaryServer<>"" $GetIPOptions=$GetIPOptions + "," + $objNetAdapter.WINSSecondaryServer endif case 1 select case $setting="DefaultGW" or $setting="DefaultGateway" or $setting="Gateway" $setting="DefaultIPGateway" case $setting="DNSServers" $setting="DNSServerSearchOrder" case $setting="StaticIP" or $setting="Static" $setting="DHCPEnabled" $toggle=1 endselect $=execute("$" + "GetIPOptions=" + "$" + "objNetAdapter." + $setting) select case vartype($GetIPOptions)>=8192 ;array $GetIPOptions=join($GetIPOptions,",") case vartype($GetIPOptions)=11 ;boolean if $GetIPOptions=0 - $toggle $GetIPOptions="False" else $GetIPOptions="True" endif endselect endselect endif Next endfunction
Everything worked just fine, however it only reported the last active NIC for systems that had multiple active NIC's
_________________________
Today is the tomorrow you worried about yesterday.
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 628 anonymous users online.
|
|
|