Page 1 of 1 1
Topic Options
#154577 - 2006-01-04 09:06 PM Retrieve WINS and DNS
dataspike Offline
Getting the hang of it

Registered: 2005-03-09
Posts: 89
Loc: San Diego, CA
I'm totally lost when it comes to WMI based calls and was wondering if anyone could shed some light?

All I need to specifically retrieve (not set) the WINS, DNS, and Default GW.

I've looked at a lot of the UDF's and can only find things to set, not just read.

Any help would be awesome.

Thanks,
Chris

Code:

$CurrentIP=EnumIPInfo(0,0)
$CurrentGW=EnumIPInfo(0,3)
$CurrentSM=EnumIPInfo(0,1)

$ComputerName = @WKSTA
$Username = @USERID

$msg = MessageBox("OS Version: " + @PRODUCTTYPE + @CRLF +
"Computer: " + @WKSTA + @CRLF +
@CRLF +
"IP: " + $CurrentIP + @CRLF +
"Subnet: " + $CurrentSM + @CRLF +
"Gateway: " + $CurrentGW + @CRLF +
@CRLF +
"Username: " + @USERID, "Computer Information",64)



Edited by dataspike (2006-01-04 09:46 PM)

Top
#154578 - 2006-01-05 12:47 AM Re: Retrieve WINS and DNS
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm...
here is wins and dhcp but no DNS nor defaultGW
Code:

Break On
$strComputer = "."
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration",,48)
For each $objItem in $colItems
"Description: " + $objItem.Description ?
"DHCPServer: " + $objItem.DHCPServer ?
"MACAddress: " + $objItem.MACAddress ?
"WINSEnableLMHostsLookup: " + $objItem.WINSEnableLMHostsLookup ?
"WINSHostLookupFile: " + $objItem.WINSHostLookupFile ?
"WINSPrimaryServer: " + $objItem.WINSPrimaryServer ?
"WINSScopeID: " + $objItem.WINSScopeID ?
"WINSSecondaryServer: " + $objItem.WINSSecondaryServer ?
?
Next
? 'Press Any Key to close the window'
get $

_________________________
!

download KiXnet

Top
#154579 - 2006-01-06 04:35 PM Re: Retrieve WINS and DNS
dataspike Offline
Getting the hang of it

Registered: 2005-03-09
Posts: 89
Loc: San Diego, CA
Cool... that's a start. Thanks!

Anyone else?

Top
#154580 - 2006-01-09 08:06 AM Re: Retrieve WINS and DNS
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4548
Loc: USA
See if this will help: RFC - GetIPOptions()
Top
#154581 - 2006-01-09 09:37 PM Re: Retrieve WINS and DNS
dataspike Offline
Getting the hang of it

Registered: 2005-03-09
Posts: 89
Loc: San Diego, CA
Allen, I'll say it here too! You freaking rock!
Top
#154582 - 2006-01-10 05:41 PM Re: Retrieve WINS and DNS
dataspike Offline
Getting the hang of it

Registered: 2005-03-09
Posts: 89
Loc: San Diego, CA
Here's what all the work went to...

Allen, thanks again for the help.



Code:


$System = CreateObject("Kixtart.System")

;KD START

;************* Form **************
$Form = $System.Form()
$Form.BackColor = 212,208,200
$Form.Font = $System.Font("Verdana",8.25,0)
$Form.Height = 320
$Form.Left = 332
$Form.MaximizeBox = "False"
$Form.Text = "Computer Information"
$Form.Top = 368
$Form.Width = 400
$Form.Center
$Form.TopMost = 1
$Form.BorderStyle = 1
$Form.SysMenu = 0
$Form.Icon = $System.Icon.FromFile("myicon.ico")
;**************************************

;************* OS_Label **************
$OS_Label = $Form.Controls.Label()
$OS_Label.BackColor = 212,208,200
$OS_Label.Font = $System.Font("Verdana",8.25,0)
$OS_Label.Height = 20
$OS_Label.Left = 10
$OS_Label.Text = "Operating System:"
$OS_Label.TextAlign = 64
$OS_Label.Top = 10
$OS_Label.Width = 110
;**************************************

;************* ComputerName_Label **************
$ComputerName_Label = $Form.Controls.Label()
$ComputerName_Label.BackColor = 212,208,200
$ComputerName_Label.Font = $System.Font("Verdana",8.25,0)
$ComputerName_Label.Height = 20
$ComputerName_Label.Left = 10
$ComputerName_Label.Text = "Computer Name:"
$ComputerName_Label.TextAlign = 64
$ComputerName_Label.Top = 30
$ComputerName_Label.Width = 110
;**************************************

;************* IP_Groupbox **************
$IP_Groupbox = $Form.Controls.GroupBox()
$IP_Groupbox.BackColor = 212,208,200
$IP_Groupbox.Font = $System.Font("Verdana",8.25,0)
$IP_Groupbox.Height = 205
$IP_Groupbox.Left = 10
$IP_Groupbox.Text = "IP Information"
$IP_Groupbox.Top = 50
$IP_Groupbox.Width = 375
;**************************************

;************* IP_Label **************
$IP_Label = $IP_Groupbox.Controls.Label()
$IP_Label.BackColor = 212,208,200
$IP_Label.Font = $System.Font("Verdana",8.25,0)
$IP_Label.Height = 20
$IP_Label.Left = 10
$IP_Label.Text = "IP Address:"
$IP_Label.TextAlign = 64
$IP_Label.Top = 20
$IP_Label.Width = 100
;**************************************

;************* SM_Label **************
$SM_Label = $IP_Groupbox.Controls.Label()
$SM_Label.BackColor = 212,208,200
$SM_Label.Font = $System.Font("Verdana",8.25,0)
$SM_Label.Height = 20
$SM_Label.Left = 10
$SM_Label.Text = "Subnet Mask:"
$SM_Label.TextAlign = 64
$SM_Label.Top = 40
$SM_Label.Width = 100
;**************************************

;************* DefaultGW_Label **************
$DefaultGW_Label = $IP_Groupbox.Controls.Label()
$DefaultGW_Label.BackColor = 212,208,200
$DefaultGW_Label.Font = $System.Font("Verdana",8.25,0)
$DefaultGW_Label.Height = 20
$DefaultGW_Label.Left = 10
$DefaultGW_Label.Text = "Gateway:"
$DefaultGW_Label.TextAlign = 64
$DefaultGW_Label.Top = 60
$DefaultGW_Label.Width = 100
;**************************************

;************* PDNS_Label **************
$PDNS_Label = $IP_Groupbox.Controls.Label()
$PDNS_Label.BackColor = 212,208,200
$PDNS_Label.Font = $System.Font("Verdana",8.25,0)
$PDNS_Label.Height = 20
$PDNS_Label.Left = 10
$PDNS_Label.Text = "DNS Servers:"
$PDNS_Label.TextAlign = 64
$PDNS_Label.Top = 80
$PDNS_Label.Width = 100
;**************************************

;************* WINS_Label **************
$WINS_Label = $IP_Groupbox.Controls.Label()
$WINS_Label.BackColor = 212,208,200
$WINS_Label.Font = $System.Font("Verdana",8.25,0)
$WINS_Label.Height = 20
$WINS_Label.Left = 10
$WINS_Label.Text = "WINS Server:"
$WINS_Label.TextAlign = 64
$WINS_Label.Top = 120
$WINS_Label.Width = 100
;**************************************

;************* DHCP_Label **************
$DHCP_Label = $IP_Groupbox.Controls.Label()
$DHCP_Label.BackColor = 212,208,200
$DHCP_Label.Font = $System.Font("Verdana",8.25,0)
$DHCP_Label.Height = 20
$DHCP_Label.Left = 10
$DHCP_Label.Text = "DHCP Server:"
$DHCP_Label.TextAlign = 64
$DHCP_Label.Top = 160
$DHCP_Label.Width = 100
;**************************************

;************* Static_Checkbox **************
$Static_Checkbox = $IP_Groupbox.Controls.CheckBox()
$Static_Checkbox.BackColor = 212,208,200
$Static_Checkbox.CheckAlign = 16
$Static_Checkbox.Enabled = "False"
$Static_Checkbox.Font = $System.Font("Verdana",8.25,0)
$Static_Checkbox.Height = 20
$Static_Checkbox.Left = 10
$Static_Checkbox.TabStop = "False"
$Static_Checkbox.Text = "Static IP Address"
$Static_Checkbox.Top = 180
$Static_Checkbox.Width = 125
;**************************************

;************* DHCP_Checkbox **************
$DHCP_Checkbox = $IP_Groupbox.Controls.CheckBox()
$DHCP_Checkbox.BackColor = 212,208,200
$DHCP_Checkbox.CheckAlign = 16
$DHCP_Checkbox.Enabled = "False"
$DHCP_Checkbox.Font = $System.Font("Verdana",8.25,0)
$DHCP_Checkbox.Height = 20
$DHCP_Checkbox.Left = 160
$DHCP_Checkbox.TabStop = "False"
$DHCP_Checkbox.Text = "DHCP Enabled"
$DHCP_Checkbox.Top = 180
$DHCP_Checkbox.Width = 110
;**************************************

;************* OK_Button **************
$OK_Button = $Form.Controls.Button()
$OK_Button.Font = $System.Font("Verdana",8.25,0)
$OK_Button.Height = 23
$OK_Button.Left = 310
$OK_Button.Text = "OK"
$OK_Button.Top = 265
$OK_Button.Width = 75
$OK_Button.OnClick = "Quit"
;**************************************

;************* OS_Results **************
$OS_Results = $Form.Controls.Label()
$OS_Results.BackColor = 212,208,200
$OS_Results.Font = $System.Font("Verdana",8.25,0)
$OS_Results.Height = 20
$OS_Results.Left = 130
$OS_Results.Text = "@PRODUCTTYPE - @CSD"
$OS_Results.TextAlign = 16
$OS_Results.Top = 10
$OS_Results.Width = 250
;**************************************

;************* ComputerName_Results **************
$ComputerName_Results = $Form.Controls.Label()
$ComputerName_Results.BackColor = 212,208,200
$ComputerName_Results.Font = $System.Font("Verdana",8.25,0)
$ComputerName_Results.Height = 20
$ComputerName_Results.Left = 130
$ComputerName_Results.Text = "@WKSTA"
$ComputerName_Results.TextAlign = 16
$ComputerName_Results.Top = 30
$ComputerName_Results.Width = 100
;**************************************

;************* IP_Results **************
$IP_Results = $IP_Groupbox.Controls.Label()
$IP_Results.BackColor = 212,208,200
$IP_Results.Font = $System.Font("Verdana",8.25,0)
$IP_Results.Height = 20
$IP_Results.Left = 120
$IP_Results.TextAlign = 16
$IP_Results.Top = 20
$IP_Results.Width = 240
;**************************************

;************* SM_Results **************
$SM_Results = $IP_Groupbox.Controls.Label()
$SM_Results.BackColor = 212,208,200
$SM_Results.Font = $System.Font("Verdana",8.25,0)
$SM_Results.Height = 20
$SM_Results.Left = 120
$SM_Results.TextAlign = 16
$SM_Results.Top = 40
$SM_Results.Width = 240
;**************************************

;************* GW_Results **************
$GW_Results = $IP_Groupbox.Controls.Label()
$GW_Results.BackColor = 212,208,200
$GW_Results.Font = $System.Font("Verdana",8.25,0)
$GW_Results.Height = 20
$GW_Results.Left = 120
$GW_Results.TextAlign = 16
$GW_Results.Top = 60
$GW_Results.Width = 240
;**************************************

;************* PDNS_Results **************
$PDNS_Results = $IP_Groupbox.Controls.Label()
$PDNS_Results.BackColor = 212,208,200
$PDNS_Results.Font = $System.Font("Verdana",8.25,0)
$PDNS_Results.Height = 20
$PDNS_Results.Left = 120
$PDNS_Results.TextAlign = 16
$PDNS_Results.Top = 80
$PDNS_Results.Width = 240
;**************************************

;************* SDNS_Results **************
$SDNS_Results = $IP_Groupbox.Controls.Label()
$SDNS_Results.BackColor = 212,208,200
$SDNS_Results.Font = $System.Font("Verdana",8.25,0)
$SDNS_Results.Height = 20
$SDNS_Results.Left = 120
$SDNS_Results.TextAlign = 16
$SDNS_Results.Top = 100
$SDNS_Results.Width = 240
;**************************************

;************* PWINS_Results **************
$PWINS_Results = $IP_Groupbox.Controls.Label()
$PWINS_Results.BackColor = 212,208,200
$PWINS_Results.Font = $System.Font("Verdana",8.25,0)
$PWINS_Results.Height = 20
$PWINS_Results.Left = 120
$PWINS_Results.TextAlign = 16
$PWINS_Results.Top = 120
$PWINS_Results.Width = 240
;**************************************

;************* SWINS_Results **************
$SWINS_Results = $IP_Groupbox.Controls.Label()
$SWINS_Results.BackColor = 212,208,200
$SWINS_Results.Font = $System.Font("Verdana",8.25,0)
$SWINS_Results.Height = 20
$SWINS_Results.Left = 120
$SWINS_Results.TextAlign = 16
$SWINS_Results.Top = 140
$SWINS_Results.Width = 240
;**************************************

;************* DHCP_Results **************
$DHCP_Results = $IP_Groupbox.Controls.Label()
$DHCP_Results.BackColor = 212,208,200
$DHCP_Results.Font = $System.Font("Verdana",8.25,0)
$DHCP_Results.Height = 20
$DHCP_Results.Left = 120
$DHCP_Results.TextAlign = 16
$DHCP_Results.Top = 160
$DHCP_Results.Width = 240
;**************************************


;KD END

$Static_Status = getipoptions("StaticIP")
If $Static_Status = "True"
$Static_Checkbox.Checked = "True"
EndIf

$DHCP_Status = getipoptions("DHCPEnabled")
If $DHCP_Status = "True"
$DHCP_Checkbox.Checked = "True"
EndIf

$GetIP = getipoptions("IPAddress")
If InStr($GetIP,",") ;If true, then comma found
$IP_SM_Array = Split($GetIP,",")
$Actual_IP = $IP_SM_Array[0]
$Actual_SM = $IP_SM_Array[1]
$IP_Results.Text = "$Actual_IP"
$SM_Results.Text = "$Actual_SM"
EndIf

$GW_Results.Text = getipoptions("DefaultGW")

$GetDNS = getipoptions("DNSServers")
If InStr($GetDNS,",") ;If true, then comma found
$DNS_Array = Split($GetDNS,",")
$PrimaryDNS = $DNS_Array[0]
$SecondaryDNS = $DNS_Array[1]
If Len($PrimaryDNS) > 3
$PDNS_Results.Text = "$PrimaryDNS" + " (Primary)"
EndIf
If Len($SecondaryDNS) > 3
$SDNS_Results.Text = "$SecondaryDNS" + " (Secondary)"
EndIf
EndIf

$GetWINS = getipoptions("WINSServers")
If InStr($GetWINS,",") ;If true, then comma found
$WINS_Array = Split($GetWINS,",")
$PrimaryWINS = $WINS_Array[0]
$SecondaryWINS = $WINS_Array[1]
If Len($PrimaryWINS) > 3
$PWINS_Results.Text = "$PrimaryWINS" + " (Primary)"
EndIf
If Len($SecondaryWINS) > 3
$SWINS_Results.Text = "$SecondaryWINS" + " (Secondary)"
EndIf
EndIf

$DHCP_Results.Text = getipoptions("DHCPServer")

$OK_Button.SetFocus

$Form.Show
While $Form.Visible
$=Execute($Form.DoEvents())
Loop
Exit 1

;$=SetOption("Wrapateol","on")
;$=SetOption("Explicit","on")
;$=SetOption("NoVarsinstrings","on")
;$=SetOption("NoMacrosinstrings","on")


;? " 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")

;Get $

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


Top
#154583 - 2006-01-10 09:56 PM Re: Retrieve WINS and DNS
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4548
Loc: USA
Really glad to help you out.

Looks like you made something similar to WINIPCFG that used on come on Win9x. I think its in a resource kit or on the CD somewhere for the NT based OSs though. Anyway, nice work.

I haven't had much time since I posted the function, but I'm still working on it, and there may be a few changes... but it shouldn't affect you too much.

Top
#154584 - 2006-01-11 04:34 PM Re: Retrieve WINS and DNS
dataspike Offline
Getting the hang of it

Registered: 2005-03-09
Posts: 89
Loc: San Diego, CA
Quote:

Really glad to help you out.

Looks like you made something similar to WINIPCFG that used on come on Win9x. I think its in a resource kit or on the CD somewhere for the NT based OSs though. Anyway, nice work.

I haven't had much time since I posted the function, but I'm still working on it, and there may be a few changes... but it shouldn't affect you too much.



Very true... WINIPCFG is originally what gave me the idea. However I am going to be puttin in some other fields, so it'll be an all in one product so to speak. Again, thanks for your help!

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 596 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.058 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org