I am looking to run a script to see who has DHCP turned on or who has a Static ip address. I found some code on the kixtart forum that looked like it would do the trick but i keep getting array errors. It would be nice if i could get mac address as well. Looking through the code it seems like it should work but i cant figure out where its all going bad.
Code:
Break On
Dim $SO,$Pause
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('WrapAtEOL','On')
Dim $Array, $X, $Y
; Declare the COMPUTER var if not defined on the command line
If Not IsDeclared($COMPUTER)
Global $COMPUTER
EndIf
$Array = NicInfo($COMPUTER)
If UBound($Array) < 0
@SERROR ?
Else
UBound($Array) ' elements returned.' ?
For $X = 0 to UBound($Array)
For $Y = 0 to UBound($Array[$X])
$y '. ' $Array[$X][$Y] ?
Next
Next
EndIf
;;======================================================================
;;
;;FUNCTION NicInfo()
;;
;;ACTION Returns an array NIC information
;;
;;AUTHOR Glenn Barnas / NTDoc
;;
;;VERSION 1.0
;;
;;DATE CREATED 2005/03/17
;;
;;DATE MODIFIED
;;
;;SYNTAX NicInfo(target)
;;
;;PARAMETERS target - name of sysetm to query
;;
;;REMARKS Array of arrays is returned - a collection of arrays for each physical or virtual NIC
;; WAN/RAS, and Miniport drivers are ignored
;;
;;RETURNS Array of Arrays
;;
;;DEPENDENCIES none
;;
;;TESTED WITH NT4, W2K, WXP
;;
;;EXAMPLES $Array = NicInfo($COMPUTER)
;;
;; If UBound($Array) < 0
;; @SERROR ?
;; Else
;;
;; UBound($Array) ' elements returned.' ?
;;
;; For $X = 0 to UBound($Array)
;; For $Y = 0 to UBound($Array[$X])
;; $y '. ' $Array[$X][$Y] ?
;; Next
;; Next
;; EndIf
;;
;
Function NicInfo(OPTIONAL $Target)
Dim $Regkey, $SubKeyCounter, $NicArray, $CurrentSubKey, $Index
Dim $Name, $Key, $WorkRegKey, $SubKey
; Insure $Target uses the format "\\target\" if specified
$Target = IIf($Target <> '', '\\' + Join(Split($Target, '\'), '', 3) + '\', '')
; Define the primary registry key $RegKey = $Target + 'HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}'
; init the enumeration index and array index
$SubKeyCounter = 0
$Index = 0
; Enumerate all of the keys that are LAN adapters
$CurrentSubKey = EnumKey($RegKey, $SubKeyCounter)
If @ERROR
Exit @ERROR ; exit now if can't read registry!
EndIf
$CurrentSubKey = EnumKey($RegKey, $SubKeyCounter)
While @ERROR = 0
$Key = ReadValue($RegKey + '\' + $CurrentSubKey, 'Characteristics')
If $Key = 132 Or $Key = 32769 ; physical nic or virtual team
ReDim Preserve $NicArray[$Index] ; increase the array size
$NicArray[$Index] = $CurrentSubKey ; add the subkey to the array
$Index = $Index + 1 ; increment the array index
EndIf
$SubKeyCounter = $SubKeyCounter + 1 ; increment the enumeration index
$CurrentSubKey = EnumKey($RegKey, $SubKeyCounter) ; get the next key
Loop
; Have an array of all the NIC subkeys now... Gather some appropriate data on each
Dim $NicData[UBound($NicArray)]
$Index = 0
Dim $WorkArray[14]
For Each $SubKey In $NicArray
; Start by determining the Speed/Duplex value name
$SubKeyCounter = 0
$Name = ''
$WorkRegKey = $RegKey + '\' + $SubKey + '\Ndi\Params'
; Enumerate all of the subkeys to locate the Speed/Duplex value name
$CurrentSubKey = EnumKey($WorkRegKey, $SubKeyCounter)
While @ERROR = 0 And $Name = ''
$Key = ReadValue($WorkRegKey + '\' + $CurrentSubKey, 'ParamDesc')
If InStr($Key, 'Duplex') Or InStr($Key, 'Connection Type')
$Name = $CurrentSubKey ; Save the Key Name
EndIf
$SubKeyCounter = $SubKeyCounter + 1 ; increment the enumeration index
$CurrentSubKey = EnumKey($WorkRegKey, $SubKeyCounter) ; get the next key
Loop ; enumerate subkeys
; Collect the data for this adapter
$WorkArray[0] = ReadValue($RegKey + '\' + $SubKey, 'DriverDesc') ; Adapter Description
$WorkArray[1] = ReadValue($RegKey + '\' + $SubKey, 'ProviderName') ; Manufacturer
$WorkArray[2] = ReadValue($RegKey + '\' + $SubKey, 'NetCfgInstanceId') ; NIC GUID
$WorkArray[3] = ReadValue($RegKey + '\' + $SubKey, $Name) ; Speed/Duplex value
$WorkArray[4] = ReadValue($WorkRegKey + '\' + $Name + '\Enum', $WorkArray[3]) ; Speed/Duplex text
$WorkArray[5] = ReadValue($RegKey + '\' + $SubKey, 'DriverVersion') ; Driver Version
$WorkRegKey = $Target + 'HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\' + $WorkArray[2]
$WorkArray[6] = ReadValue($WorkRegKey, 'EnableDHCP') ; DHCP boolean
$Key = IIf($WorkArray[6] = 1, 'Dhcp', '')
$WorkArray[7] = ReadStringValue($WorkRegKey, $Key + 'IPAddress') + ',' +
ReadStringValue($WorkRegKey, $Key + 'SubnetMask') + ',' +
ReadStringValue($WorkRegKey, $Key + 'DefaultGateway') ; IP settings
$WorkArray[8] = ReadStringValue($WorkRegKey, $Key + 'Domain') ; Domain Name
$WorkArray[9] = ReadStringValue($WorkRegKey, $Key + 'NameServer') ; DNS Server list
; handle an undefined speed/duplex setting
If $WorkArray[4] = ''
$WorkArray[4] = 'Undefined'
EndIf ; undefined speed
; Special values for Compaq/HP Team
If ReadValue($RegKey + '\' + $SubKey, 'Characteristics') = 32769
$WorkArray[10] = 'HPTEAM' ; special flag
$WorkArray[11] = ReadValue($RegKey + '\' + $SubKey, 'TeamAdapters') ; # of adapters in team $WorkArray[12] = ReadValue($RegKey + '\' + $SubKey, 'TeamInstances') ; ID of adapters in team
EndIf
$NicData[$Index] = $WorkArray
$Index = $Index + 1
ReDim $WorkArray[14]
Next ; CurrentSubKey
; Return the array of arrays
ReDim Preserve $NicData[$Index - 1]
$NicInfo = $NicData
EndFunction
; Read a String_Multi_SZ val and return a space-delimited string
Function ReadStringValue($Key, $Val)
$ReadStringValue = Trim(Join(Split(ReadValue($Key, $Val), '|'), ' '))
EndFunction
ERROR:
Code:
ERROR : array reference out of bounds!
Script: c:\test\dhcp\dhcp.kix
Line : 98
When i tried to do a ? $NicData or ? $NicArray i still got an error without it showing me what information was in them. i put them in around line 97, right above where the error was happing.
_________________________
Where ever you go, there you are.
For some trouble shooting i have done the following
Code:
Dim $Array, $X, $Y
$Computer = corp_tesdall
; Declare the COMPUTER var if not defined on the command line
; If Not IsDeclared($COMPUTER)
;Global $COMPUTER
;EndIf
Still get an error down on line 101 now. which is still Dim $NicData[UBound($NicArray)]. I copied and pasted this UDF, i must have messed something up.
_________________________
Where ever you go, there you are.
See the crlf? Altered original udf code -> Fail Additionally: Your $Computer Variable is 'empty', thus useless. If you want to query Remote Systems, feed the udf with a Hostname, otherwise, for local queries, just omit the optional Value.
As the UDFs are not always named what i would have named them, i would like to thank you for pointing that one out. That's exactly what i wanted. I will post the script that works as of right now for my local machine only. I will be adding the abbility to scan remote computerss from a list and do a loop and pulling out all of the information to a CSV. Once im done that, i will post that script.
Code:
break on
$remotepc="@WKSTA"
for each $nc in Enumnetworkconnections(3,$remotepc)
$ConnectionName=split($nc,",")[0]
$MACAddress=split($nc,",")[1]
$AdapterName=split($nc,",")[2]
? " Connection Name: " + $connectionname
? " MACAddress: " + $MACAddress
? " Adapter Name: " + $AdapterName
? " Mac Address: " + getipoptions("Macaddress",$remotepc,$macaddress)
? " Static Address: " + getipoptions("StaticIP",$remotepc,$macaddress)
? " DHCP Enabled: " + getipoptions("DHCPEnabled",$remotepc,$macaddress)
? " IPaddress/SM: " + getipoptions("IPAddress",$remotepc,$macaddress)
? " IPaddress0/SM: " + getipoptions("IPAddress0",$remotepc,$macaddress)
? " IPaddress1/SM: " + getipoptions("IPAddress1",$remotepc,$macaddress)
? " IPaddress2/SM: " + getipoptions("IPAddress2",$remotepc,$macaddress)
? " IPaddress3/SM: " + getipoptions("IPAddress3",$remotepc,$macaddress)
? " DefaultGW: " + getipoptions("DefaultGW",$remotepc,$macaddress)
? " DNS Servers: " + getipoptions("DNSServers",$remotepc,$macaddress)
? " WINS Servers: " + getipoptions("WINSServers",$remotepc,$macaddress)
? " DNSSuffix: " + getipoptions("DNSDomain",$remotepc,$macaddress)
? " DNS Search Order: " + getipoptions("DNSDomainSuffixSearchOrder",$remotepc,$macaddress)
? " DHCP Server: " + getipoptions("DHCPServer",$remotepc,$macaddress)
? "DHCP Lease Obtained: " + getipoptions("DHCPLeaseObtained",$remotepc,$macaddress)
? " DHCP Lease Expires: " + getipoptions("DHCPLeaseExpires",$remotepc,$macaddress)
? "---------------"
;Function:
; GetIPOptions()
;
;Author:
; Allen Powell
;
;Version:
; 1.0 2006/03/15
;
;Action:
; Display/Get IP Settings
;
;Syntax:
; GetIPOptions($Setting,optional $remotepc, optional $macaddress)
;
;Parameters:
; $setting - Any valid property from Win32_NetworkAdapterConfiguration class, See examples below and
;
;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_networkadapterconfiguration.asp
; $remotepc - (Optional) Remote Computer Name
; $macaddress - (Optional) In Computers with more than Network Adapter, provide the MACAddress to target it settings
;
;Returns:
; String containing setting
;
;Dependencies
; WMI with Windows XP, Windows 2000 Professional, or Windows NT Workstation 4.0 SP4 and later
; Tested with Kixtart 4.52 Beta
;
;Notes
; If a computer has more than one Network Adapter and the macaddress is not provided it will return the last adapter's ;
information
;
;Example1:
;
;? " Mac Address: " + getipoptions("Macaddress")
;? " 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")
;? " DNS Servers: " + getipoptions("DNSServers")
;? " 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")
;
;Example2: List settings for Remote Computers including those with more than one Network Adapter.
; Requires EnumNetworkConnections() - http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=138769&an=0&page=0#138769
;
;break on
;$remotepc="computername"
;for each $nc in Enumnetworkconnections(3,$remotepc)
; $ConnectionName=split($nc,",")[0]
; $MACAddress=split($nc,",")[1]
; $AdapterName=split($nc,",")[2]
; ? " Connection Name: " + $connectionname
; ? " MACAddress: " + $MACAddress
; ? " Adapter Name: " + $AdapterName
; ? " Mac Address: " + getipoptions("Macaddress",$remotepc,$macaddress)
; ? " Static Address: " + getipoptions("StaticIP",$remotepc,$macaddress)
; ? " DHCP Enabled: " + getipoptions("DHCPEnabled",$remotepc,$macaddress)
; ? " IPaddress/SM: " + getipoptions("IPAddress",$remotepc,$macaddress)
; ? " IPaddress0/SM: " + getipoptions("IPAddress0",$remotepc,$macaddress)
; ? " IPaddress1/SM: " + getipoptions("IPAddress1",$remotepc,$macaddress)
; ? " IPaddress2/SM: " + getipoptions("IPAddress2",$remotepc,$macaddress)
; ? " IPaddress3/SM: " + getipoptions("IPAddress3",$remotepc,$macaddress)
; ? " DefaultGW: " + getipoptions("DefaultGW",$remotepc,$macaddress)
; ? " DNS Servers: " + getipoptions("DNSServers",$remotepc,$macaddress)
; ? " WINS Servers: " + getipoptions("WINSServers",$remotepc,$macaddress)
; ? " DNSSuffix: " + getipoptions("DNSDomain",$remotepc,$macaddress)
; ? " DNS Search Order: " + getipoptions("DNSDomainSuffixSearchOrder",$remotepc,$macaddress)
; ? " DHCP Server: " + getipoptions("DHCPServer",$remotepc,$macaddress)
; ? "DHCP Lease Obtained: " + getipoptions("DHCPLeaseObtained",$remotepc,$macaddress)
; ? " DHCP Lease Expires: " + getipoptions("DHCPLeaseExpires",$remotepc,$macaddress)
; ? "---------------"
;next
;
;
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
;Function:
; EnumNetworkConnections()
;
;Author:
; Allen Powell
;
;Version:
; 2.0 2006/03/15 Complete Re-write (backward compatible)
; 1.0 2005/05/11 Original Version - Returned just the "Connection Name"
;
;Action:
; Enumerates/Lists the Network Connections names
;
;Syntax:
; EnumNetworkConnections(optional $mode, optional $remotepc)
;
;Parameters:
; $mode - (Optional) Numeric expression that is the sum of values below
; - 0 Connection Name (default)
; - 1 MACAddress
; - 2 Network Adapter Name
;
; $remotepc - (Optional) Remote Computer Name
;
;Returns:
; Array of Network Connection Names, optionally with MACAddress and/or Name of the Network Card
;
;Dependencies
; WMI with Windows XP, Windows 2000 Professional, or Windows NT Workstation 4.0 SP4 and later
; Tested with Kixtart 4.52 Beta
;Example:
;
;for each $nc in Enumnetworkconnections()
; ? $NC
;next
;
function EnumNetworkConnections(optional $mode,optional $remotepc)
dim $NCs[0],$objWMIService,$colItems,$objItem,$counter
if $remotepc=""
$remotepc="."
endif
$objWMIService = GetObject("winmgmts:\\" + $remotepc + "\root\cimv2")
if @error
exit @error
endif
$colItems = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapter where (MACAddress is not null) and
(NetConnectionID is not null)")
For each $objItem in $colItems
redim preserve $NCs[$counter]
$NCs[$counter]=$objItem.NetConnectionID
if $mode & 1
$NCs[$counter]=$NCs[$counter] + "," + $objItem.MACAddress
endif
if $mode & 2
$NCs[$counter]=$NCs[$counter] + "," + $objItem.Name
endif
$counter=$counter + 1
Next
$EnumNetworkConnections=$NCs
endfunction
_________________________
Where ever you go, there you are.
I can certainly relate on the names... When I wrote that, there were so many other existing enum/IP UDFs that my options to name it were pretty limited.
First, it generates a TXT file with the headers of ever row. It then reads from a list of computers i exported from Active directory. It Pings the computer to see if it is online. (ping is a UDF) Once it determines that the machine is online it then runs the UDFs to see how many network cards and what the settings are for the network cards. It writes that information to the TXT file. then it loops
I manually change the dhcporstatic.txt to a CSV to view the results.
The Three UDFs are in the script but they are the following: ping(), GetIPOptions() and EnumNetworkConnections().
Code:
Break on
; Declare variables to prevent scope creep
Dim $InFile, $OutFile, $Offline ; file names for input and output
Dim $remotepc ; computer name, from input file
Dim $Rc ; return-code catcher
Dim $Version ; Version data from Computer
$Rc = SetOption('NoVarsInStings', 'On')
$OutFile = ('c:\test\DHCP\DHCPorStatic.txt')
$InFile = ('c:\test\DHCP\computerlist.txt')
$Offline = ('c:\test\DHCP\Offline.txt')
; Open the input file - no strings in quotes!
If Open( 1 , $InFile) <> 0
'Failed to open ' $InFile ' - aborting!' ?
Exit 1
EndIf
; same for the output file
If Open( 2 , $OutFile, 5) <> 0
'Failed to open ' $OutFile ' - aborting!' ?
Exit 1
EndIf
; same for the offline file
If Open( 3 , $Offline, 5) <> 0
'Failed to open ' $Offline ' - aborting!' ?
Exit 1
EndIf
$Rc = WriteLine(2, 'Remotepc' + ',' + 'ConnectionName' + ',' + 'AdapterName' + ',' + 'Mac Address' + ',' + 'Static Address' +
',' + 'DHCP Enabled' + ',' + 'IPaddress/SM' + ',' + 'IPaddress0/SM' + ',' + 'IPaddress1/SM' + ',' + 'IPaddress2/SM' + ',' +
'IPaddress3/SM' + ',' + 'DefaultGW' + ',' + 'DNS Servers' + ',' + 'WINS Servers' + ',' + 'DNSSuffix' + ',' + 'DNS Search
Order' + ',' + 'DHCP Server' + ',' + 'DHCP Lease Obtained' + ',' + 'DHCP Lease Expires' + ',' + @CRLF)
; Read the first line, then loop until EOD (End Of Data) error
$remtoepc = ReadLine(1)
While Not @ERROR
'Computer: ' $remotepc ? ; display the current computer
; Only Communicate with the computer if it is online
If Ping($remotepc, 0) <>0
for each $nc in Enumnetworkconnections(3,$remotepc)
$ConnectionName=split($nc,",")[0]
$MACAddress=split($nc,",")[1]
$AdapterName=split($nc,",")[2]
$Rc = WriteLine(2, $remotepc + ',' + $connectionname + ',' + $AdapterName + ',' +
getipoptions("Macaddress",$remotepc,$macaddress) + ',' + getipoptions("StaticIP",$remotepc,$macaddress) + ',' +
getipoptions("DHCPEnabled",$remotepc,$macaddress) + ',' + getipoptions("IPAddress",$remotepc,$macaddress) + ',' +
getipoptions("IPAddress0",$remotepc,$macaddress) + ',' + getipoptions("IPAddress1",$remotepc,$macaddress) + ',' +
getipoptions("IPAddress2",$remotepc,$macaddress) + ',' + getipoptions("IPAddress3",$remotepc,$macaddress) + ',' +
getipoptions("DefaultGW",$remotepc,$macaddress) + ',' + getipoptions("DNSServers",$remotepc,$macaddress) + ',' +
getipoptions("WINSServers",$remotepc,$macaddress) + ',' + getipoptions("DNSDomain",$remotepc,$macaddress) + ',' +
getipoptions("DNSDomainSuffixSearchOrder",$remotepc,$macaddress) + ',' + getipoptions("DHCPServer",$remotepc,$macaddress) +
',' + getipoptions("DHCPLeaseObtained",$remotepc,$macaddress) + ',' + getipoptions("DHCPLeaseExpires",$remotepc,$macaddress)
+ @CRLF)
next
Else
$Rc = WriteLine(3, $remotepc + @CRLF)
Endif
$remotepc = ReadLine(1)
Loop
$Rc = Close(1)
$Rc = Close(2)
;;======================================================================
;;
;;FUNCTION ping()
;;
;;ACTION ping - Pings a host
;;
;;AUTHOR Glenn Barnas
;;
;;VERSION 2.0 - 2007/10/20 - WHS version
;; 1.0 - based on KORG Ping UDF by Jochen Polster, enhanced to
;; return values and IP's
;;
;;SYNTAX ping(host, [Flag], [Wait])
;;
;;PARAMETERS host - name of host to ping
;; FLAG - if negative, returns IP Address
;; if >0, specifies number of tries (default is 1)
;; Wait - optional ping timeout value
;;
;;
;;REMARKS ERROR is set to 0 if success, 1 otherwise.
;;
;;RETURNS FLAG >= 0: returns 1 if host is reachable, 0 if not
;; FLAG < 0: Returns IP address if resolvable, 0.0.0.0 if not
;;
;;DEPENDENCIES OS Commands Ping & Find
;;
;;TESTED WITH NT4, W2K, WXP
;;
;;EXAMPLES Ping('hostname') ; returns Success/Failure
;; Ping('hostname',-1) ; returns IP Address
;
Function Ping($_Host, OPTIONAL $_Flag, OPTIONAL $_Wait)
Dim $_oExec ; WSH Object
Dim $_Tries ; # of times to ping
Dim $_Timeout ; Ping timeout value
Dim $_Response ; Response Flag
Dim $_Line ; Line returned from command string
Dim $_Cmd ; first part of command string
Dim $_Count ; current ping count
$_Flag = Val($_Flag) ; determine what to do
$_Wait = Val($_Wait) ;
$_Tries = 1 ; one ping
$_Timeout = 1000 ; 1 second timeout
; set timeout if Wait is non-zero
If $_Wait > 0
$_Timeout = $_Wait
EndIf
If $_FLAG > 0 ; Multiple pings - return on first reply
$_Tries = $_FLAG
EndIf
; Ping the host $_Tries times, but only until a response is received
$_Count = 0
; search for reply from host during PING
$_Cmd = '%COMSPEC% /c ping.exe -4 -n 1 -w ' + $_Timeout + ' ' + $_Host
If $_Flag < 0
$_Cmd = $_Cmd + ' | %SystemRoot%\System32\Find "Pinging"'
Else
$_Cmd = $_Cmd + ' | %SystemRoot%\System32\Find "Reply" | %SystemRoot%\System32\Find "TTL="'
EndIf
Do
$_oExec = CreateObject("WScript.Shell").Exec($_Cmd)
If Not VarType($_oExec)=9 $Ping = 'WScript.Shell Exec Unsupported' Exit 10 EndIf
$_Line = Split(Join(Split($_oExec.StdOut.ReadAll + $_oExec.StdErr.ReadAll,CHR(13)),''),CHR(10))[0]
$_Response = IIf($_Line, 1, 0)
If $_Response
$_Count = $_Tries
EndIf
$_Count = $_Count + 1
If $_Count < $_Tries Sleep 0.25 EndIf
Until $_Count >= $_Tries
; If FLAG >= 0, return success/failure - otherwise return IP address
If $_FLAG >= 0
$Ping = $_Response
Else
If Not $_Response
$Ping = '0.0.0.0'
Else
; In this mode we return the IP address - we should have the HOSTNAME
; handle the 'duh' factor for times when we get the IP address instead!
If InStr($_Line,'[') > 0
$Ping= Split(Join(Split($_Line,']',-1),'['), '[')[1]
Else
$Ping = Split(Split($_Line,' ',-1)[1], ':')[0]
EndIf
EndIf
EndIf
Exit Not $_Response ; set the error code
EndFunction
;Function:
; GetIPOptions()
;
;Author:
; Allen Powell
;
;Version:
; 1.0 2006/03/15
;
;Action:
; Display/Get IP Settings
;
;Syntax:
; GetIPOptions($Setting,optional $remotepc, optional $macaddress)
;
;Parameters:
; $setting - Any valid property from Win32_NetworkAdapterConfiguration class, See examples below and
;
;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_networkadapterconfiguration.asp
; $remotepc - (Optional) Remote Computer Name
; $macaddress - (Optional) In Computers with more than Network Adapter, provide the MACAddress to target it settings
;
;Returns:
; String containing setting
;
;Dependencies
; WMI with Windows XP, Windows 2000 Professional, or Windows NT Workstation 4.0 SP4 and later
; Tested with Kixtart 4.52 Beta
;
;Notes
; If a computer has more than one Network Adapter and the macaddress is not provided it will return the last adapter's ;
information
;
;Example1:
;
;? " Mac Address: " + getipoptions("Macaddress")
;? " 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")
;? " DNS Servers: " + getipoptions("DNSServers")
;? " 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")
;
;Example2: List settings for Remote Computers including those with more than one Network Adapter.
; Requires EnumNetworkConnections() - http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=138769&an=0&page=0#138769
;
;break on
;$remotepc="computername"
;for each $nc in Enumnetworkconnections(3,$remotepc)
; $ConnectionName=split($nc,",")[0]
; $MACAddress=split($nc,",")[1]
; $AdapterName=split($nc,",")[2]
; ? " Connection Name: " + $connectionname
; ? " MACAddress: " + $MACAddress
; ? " Adapter Name: " + $AdapterName
; ? " Mac Address: " + getipoptions("Macaddress",$remotepc,$macaddress)
; ? " Static Address: " + getipoptions("StaticIP",$remotepc,$macaddress)
; ? " DHCP Enabled: " + getipoptions("DHCPEnabled",$remotepc,$macaddress)
; ? " IPaddress/SM: " + getipoptions("IPAddress",$remotepc,$macaddress)
; ? " IPaddress0/SM: " + getipoptions("IPAddress0",$remotepc,$macaddress)
; ? " IPaddress1/SM: " + getipoptions("IPAddress1",$remotepc,$macaddress)
; ? " IPaddress2/SM: " + getipoptions("IPAddress2",$remotepc,$macaddress)
; ? " IPaddress3/SM: " + getipoptions("IPAddress3",$remotepc,$macaddress)
; ? " DefaultGW: " + getipoptions("DefaultGW",$remotepc,$macaddress)
; ? " DNS Servers: " + getipoptions("DNSServers",$remotepc,$macaddress)
; ? " WINS Servers: " + getipoptions("WINSServers",$remotepc,$macaddress)
; ? " DNSSuffix: " + getipoptions("DNSDomain",$remotepc,$macaddress)
; ? " DNS Search Order: " + getipoptions("DNSDomainSuffixSearchOrder",$remotepc,$macaddress)
; ? " DHCP Server: " + getipoptions("DHCPServer",$remotepc,$macaddress)
; ? "DHCP Lease Obtained: " + getipoptions("DHCPLeaseObtained",$remotepc,$macaddress)
; ? " DHCP Lease Expires: " + getipoptions("DHCPLeaseExpires",$remotepc,$macaddress)
; ? "---------------"
;next
;
;
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
;Function:
; EnumNetworkConnections()
;
;Author:
; Allen Powell
;
;Version:
; 2.0 2006/03/15 Complete Re-write (backward compatible)
; 1.0 2005/05/11 Original Version - Returned just the "Connection Name"
;
;Action:
; Enumerates/Lists the Network Connections names
;
;Syntax:
; EnumNetworkConnections(optional $mode, optional $remotepc)
;
;Parameters:
; $mode - (Optional) Numeric expression that is the sum of values below
; - 0 Connection Name (default)
; - 1 MACAddress
; - 2 Network Adapter Name
;
; $remotepc - (Optional) Remote Computer Name
;
;Returns:
; Array of Network Connection Names, optionally with MACAddress and/or Name of the Network Card
;
;Dependencies
; WMI with Windows XP, Windows 2000 Professional, or Windows NT Workstation 4.0 SP4 and later
; Tested with Kixtart 4.52 Beta
;Example:
;
;for each $nc in Enumnetworkconnections()
; ? $NC
;next
;
function EnumNetworkConnections(optional $mode,optional $remotepc)
dim $NCs[0],$objWMIService,$colItems,$objItem,$counter
if $remotepc=""
$remotepc="."
endif
$objWMIService = GetObject("winmgmts:\\" + $remotepc + "\root\cimv2")
if @error
exit @error
endif
$colItems = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapter where (MACAddress is not null) and
(NetConnectionID is not null)")
For each $objItem in $colItems
redim preserve $NCs[$counter]
$NCs[$counter]=$objItem.NetConnectionID
if $mode & 1
$NCs[$counter]=$NCs[$counter] + "," + $objItem.MACAddress
endif
if $mode & 2
$NCs[$counter]=$NCs[$counter] + "," + $objItem.Name
endif
$counter=$counter + 1
Next
$EnumNetworkConnections=$NCs
endfunction
Edited by Tesdall (2010-07-2805:58 PM)
_________________________
Where ever you go, there you are.
Your code is not quite right... you need to put the getipoptions inside the loop, otherwise you will always get the last result as your only result.
(all code below untested)
Code:
for each $nc in Enumnetworkconnections(3,$remotepc)
$ConnectionName=split($nc,",")[0]
$MACAddress=split($nc,",")[1]
$AdapterName=split($nc,",")[2]
? $ConnectionName
? $MacAddress
? $AdapterName
? "DHCPEnabled" + getipoptions("DHCPEnabled",$remotepc,$macaddress)
? "-------------"
next
To remove results you don't want.
Code:
for each $nc in Enumnetworkconnections(3,$remotepc)
$ConnectionName=split($nc,",")[0]
$MACAddress=split($nc,",")[1]
$AdapterName=split($nc,",")[2]
if instr($connectionname,"1394") or inst($connectioname,"somedeviceyoudontwant")
;skipit
else
;do your writeline
endif
next
Or to be specific of the one you do want
Code:
for each $nc in Enumnetworkconnections(3,$remotepc)
$ConnectionName=split($nc,",")[0]
$MACAddress=split($nc,",")[1]
$AdapterName=split($nc,",")[2]
if instr($connectionname,"Local Area Connection")
;do your writeline
endif
next
1. The way it seems to work is the NEXT is below the loop so it just writes all the info directly to the TXT file before it loops to the next network card in the stack and then writes it all to the TXT for that card per machine.
without changing any code this is what it displays to me: (This is from the CSV, sorry its all over the place)
2. Thank you for showing me the remove option. As i do not care about 1394 amd bluetooth.
3. That would get time consuming trying to figure out what to caputre. As there maybe a local connection 4, 5, 6...etc same with wireless. I think it would be smarter to just tell if what i don't want.
Thanks!
Edited by Tesdall (2010-07-2807:07 PM)
_________________________
Where ever you go, there you are.
Break on
; Declare variables to prevent scope creep
Dim $InFile, $OutFile, $Offline ; file names for input and output
Dim $remotepc ; computer name, from input file
Dim $Rc ; return-code catcher
Dim $Version ; Version data from Computer
$Rc = SetOption('NoVarsInStings', 'On')
$OutFile = ('c:\test\DHCP\DHCPorStatic.txt')
$InFile = ('c:\test\DHCP\computerlist.txt')
$Offline = ('c:\test\DHCP\Offline.txt')
; Open the input file - no strings in quotes!
If Open( 1 , $InFile) <> 0
'Failed to open ' $InFile ' - aborting!' ?
Exit 1
EndIf
; same for the output file
If Open( 2 , $OutFile, 5) <> 0
'Failed to open ' $OutFile ' - aborting!' ?
Exit 1
EndIf
$Rc = WriteLine(2, 'Remotepc' + ',' + 'ConnectionName' + ',' + 'AdapterName' + ',' + 'Mac Address' + ',' + 'Static Address' + ',' + 'DHCP Enabled' + ',' + 'IPaddress/SM' + ',' + @CRLF)
; same for the offline file
If Open( 3 , $Offline, 5) <> 0
'Failed to open ' $Offline ' - aborting!' ?
Exit 1
EndIf
; Read the first line, then loop until EOD (End Of Data) error
$remotepc = ReadLine(1)
While Not @ERROR
'Computer: ' $remotepc ? ; display the current computer
; Only Communicate with the computer if it is online
If Ping($remotepc, 0) <>0
for each $nc in Enumnetworkconnections(3,$remotepc)
$ConnectionName=split($nc,",")[0]
$MACAddress=split($nc,",")[1]
$AdapterName=split($nc,",")[2]
if instr($ConnectionName,"1394") or instr($ConnectionName,"bluetooth")
;skipit
else
$Rc = WriteLine(2, $remotepc + ',' + $connectionname + ',' + $AdapterName + ',' + getipoptions("MACAddress",$remotepc,$macaddress) + ',' + getipoptions("StaticIP",$remotepc,$macaddress) + ',' + getipoptions("DHCPEnabled",$remotepc,$macaddress) + ',' + getipoptions("IPAddress",$remotepc,$macaddress) + ',' + @CRLF)
endif
next
Else
$Rc = WriteLine(3, $remotepc + @CRLF)
Endif
$remotepc = ReadLine(1)
Loop
$Rc = Close(1)
$Rc = Close(2)
;;======================================================================
;;
;;FUNCTION ping()
;;
;;ACTION ping - Pings a host
;;
;;AUTHOR Glenn Barnas
;;
;;VERSION 2.0 - 2007/10/20 - WHS version
;; 1.0 - based on KORG Ping UDF by Jochen Polster, enhanced to
;; return values and IP's
;;
;;SYNTAX ping(host, [Flag], [Wait])
;;
;;PARAMETERS host - name of host to ping
;; FLAG - if negative, returns IP Address
;; if >0, specifies number of tries (default is 1)
;; Wait - optional ping timeout value
;;
;;
;;REMARKS ERROR is set to 0 if success, 1 otherwise.
;;
;;RETURNS FLAG >= 0: returns 1 if host is reachable, 0 if not
;; FLAG < 0: Returns IP address if resolvable, 0.0.0.0 if not
;;
;;DEPENDENCIES OS Commands Ping & Find
;;
;;TESTED WITH NT4, W2K, WXP
;;
;;EXAMPLES Ping('hostname') ; returns Success/Failure
;; Ping('hostname',-1) ; returns IP Address
;
Function Ping($_Host, OPTIONAL $_Flag, OPTIONAL $_Wait)
Dim $_oExec ; WSH Object
Dim $_Tries ; # of times to ping
Dim $_Timeout ; Ping timeout value
Dim $_Response ; Response Flag
Dim $_Line ; Line returned from command string
Dim $_Cmd ; first part of command string
Dim $_Count ; current ping count
$_Flag = Val($_Flag) ; determine what to do
$_Wait = Val($_Wait) ;
$_Tries = 1 ; one ping
$_Timeout = 1000 ; 1 second timeout
; set timeout if Wait is non-zero
If $_Wait > 0
$_Timeout = $_Wait
EndIf
If $_FLAG > 0 ; Multiple pings - return on first reply
$_Tries = $_FLAG
EndIf
; Ping the host $_Tries times, but only until a response is received
$_Count = 0
; search for reply from host during PING
$_Cmd = '%COMSPEC% /c ping.exe -4 -n 1 -w ' + $_Timeout + ' ' + $_Host
If $_Flag < 0
$_Cmd = $_Cmd + ' | %SystemRoot%\System32\Find "Pinging"'
Else
$_Cmd = $_Cmd + ' | %SystemRoot%\System32\Find "Reply" | %SystemRoot%\System32\Find "TTL="'
EndIf
Do
$_oExec = CreateObject("WScript.Shell").Exec($_Cmd)
If Not VarType($_oExec)=9 $Ping = 'WScript.Shell Exec Unsupported' Exit 10 EndIf
$_Line = Split(Join(Split($_oExec.StdOut.ReadAll + $_oExec.StdErr.ReadAll,CHR(13)),''),CHR(10))[0]
$_Response = IIf($_Line, 1, 0)
If $_Response
$_Count = $_Tries
EndIf
$_Count = $_Count + 1
If $_Count < $_Tries Sleep 0.25 EndIf
Until $_Count >= $_Tries
; If FLAG >= 0, return success/failure - otherwise return IP address
If $_FLAG >= 0
$Ping = $_Response
Else
If Not $_Response
$Ping = '0.0.0.0'
Else
; In this mode we return the IP address - we should have the HOSTNAME
; handle the 'duh' factor for times when we get the IP address instead!
If InStr($_Line,'[') > 0
$Ping= Split(Join(Split($_Line,']',-1),'['), '[')[1]
Else
$Ping = Split(Split($_Line,' ',-1)[1], ':')[0]
EndIf
EndIf
EndIf
Exit Not $_Response ; set the error code
EndFunction
;Function:
; GetIPOptions()
;
;Author:
; Allen Powell
;
;Version:
; 1.0 2006/03/15
;
;Action:
; Display/Get IP Settings
;
;Syntax:
; GetIPOptions($Setting,optional $remotepc, optional $macaddress)
;
;Parameters:
; $setting - Any valid property from Win32_NetworkAdapterConfiguration class, See examples below and
; ;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_networkadapterconfiguration.asp
; $remotepc - (Optional) Remote Computer Name
; $macaddress - (Optional) In Computers with more than Network Adapter, provide the MACAddress to target it settings
;
;Returns:
; String containing setting
;
;Dependencies
; WMI with Windows XP, Windows 2000 Professional, or Windows NT Workstation 4.0 SP4 and later
; Tested with Kixtart 4.52 Beta
;
;Notes
; If a computer has more than one Network Adapter and the macaddress is not provided it will return the last adapter's
; information
;
;Example1:
;
;? " Mac Address: " + getipoptions("Macaddress")
;? " 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")
;? " DNS Servers: " + getipoptions("DNSServers")
;? " 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")
;
;Example2: List settings for Remote Computers including those with more than one Network Adapter.
; Requires EnumNetworkConnections() - http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=138769&an=0&page=0#138769
;
;break on
;$remotepc="computername"
;for each $nc in Enumnetworkconnections(3,$remotepc)
; $ConnectionName=split($nc,",")[0]
; $MACAddress=split($nc,",")[1]
; $AdapterName=split($nc,",")[2]
; ? " Connection Name: " + $connectionname
; ? " MACAddress: " + $MACAddress
; ? " Adapter Name: " + $AdapterName
; ? " Mac Address: " + getipoptions("Macaddress",$remotepc,$macaddress)
; ? " Static Address: " + getipoptions("StaticIP",$remotepc,$macaddress)
; ? " DHCP Enabled: " + getipoptions("DHCPEnabled",$remotepc,$macaddress)
; ? " IPaddress/SM: " + getipoptions("IPAddress",$remotepc,$macaddress)
; ? " IPaddress0/SM: " + getipoptions("IPAddress0",$remotepc,$macaddress)
; ? " IPaddress1/SM: " + getipoptions("IPAddress1",$remotepc,$macaddress)
; ? " IPaddress2/SM: " + getipoptions("IPAddress2",$remotepc,$macaddress)
; ? " IPaddress3/SM: " + getipoptions("IPAddress3",$remotepc,$macaddress)
; ? " DefaultGW: " + getipoptions("DefaultGW",$remotepc,$macaddress)
; ? " DNS Servers: " + getipoptions("DNSServers",$remotepc,$macaddress)
; ? " WINS Servers: " + getipoptions("WINSServers",$remotepc,$macaddress)
; ? " DNSSuffix: " + getipoptions("DNSDomain",$remotepc,$macaddress)
; ? " DNS Search Order: " + getipoptions("DNSDomainSuffixSearchOrder",$remotepc,$macaddress)
; ? " DHCP Server: " + getipoptions("DHCPServer",$remotepc,$macaddress)
; ? "DHCP Lease Obtained: " + getipoptions("DHCPLeaseObtained",$remotepc,$macaddress)
; ? " DHCP Lease Expires: " + getipoptions("DHCPLeaseExpires",$remotepc,$macaddress)
; ? "---------------"
;next
;
;
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
;Function:
; EnumNetworkConnections()
;
;Author:
; Allen Powell
;
;Version:
; 2.0 2006/03/15 Complete Re-write (backward compatible)
; 1.0 2005/05/11 Original Version - Returned just the "Connection Name"
;
;Action:
; Enumerates/Lists the Network Connections names
;
;Syntax:
; EnumNetworkConnections(optional $mode, optional $remotepc)
;
;Parameters:
; $mode - (Optional) Numeric expression that is the sum of values below
; - 0 Connection Name (default)
; - 1 MACAddress
; - 2 Network Adapter Name
;
; $remotepc - (Optional) Remote Computer Name
;
;Returns:
; Array of Network Connection Names, optionally with MACAddress and/or Name of the Network Card
;
;Dependencies
; WMI with Windows XP, Windows 2000 Professional, or Windows NT Workstation 4.0 SP4 and later
; Tested with Kixtart 4.52 Beta
;Example:
;
;for each $nc in Enumnetworkconnections()
; ? $NC
;next
;
function EnumNetworkConnections(optional $mode,optional $remotepc)
dim $NCs[0],$objWMIService,$colItems,$objItem,$counter
if $remotepc=""
$remotepc="."
endif
$objWMIService = GetObject("winmgmts:\\" + $remotepc + "\root\cimv2")
if @error
exit @error
endif
$colItems = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapter where (MACAddress is not null) and (NetConnectionID is not null)")
For each $objItem in $colItems
redim preserve $NCs[$counter]
$NCs[$counter]=$objItem.NetConnectionID
if $mode & 1
$NCs[$counter]=$NCs[$counter] + "," + $objItem.MACAddress
endif
if $mode & 2
$NCs[$counter]=$NCs[$counter] + "," + $objItem.Name
endif
$counter=$counter + 1
Next
$EnumNetworkConnections=$NCs
endfunction
_________________________
Where ever you go, there you are.
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
NicInfo returns an Array of Arrays.. takes a bit of getting used to. Here's what I put together as an exercise
It outputs a CSV file directly readable by Excel or other applications. I used a single output file - the first field is the hostname, second is the NIC Index, and remaining fields are the data from NicInfo.
When an error occurs, Field 2 is "ERROR", followed by the error code and error message in fields 3 & 4.
Only the base code is shown - it uses Ping(), NicInfo(), FileIO(), and CSV() UDFs. You will need the latest version of CSV - available after 8pm today on my web site.
_________________________ Actually I am a Rocket Scientist!
It works. You just need to tell the function which network card to check by providing the Mac Address. EnumNetworkConnections is one way...
Code:
for each $nc in Enumnetworkconnections(3)
$ConnectionName=split($nc,",")[0]
$MACAddress=split($nc,",")[1]
$AdapterName=split($nc,",")[2]
if instr($ConnectionName,"Local Area Connection")
? "DHCPEnabled: " + getipoptions("DHCPEnabled",,$MacAddress)
? "-------------"
endif
next