Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

Get current DNS server through WMI?

- - - - -

  • Please log in to reply
9 replies to this topic

#1
#rootworm

#rootworm

    Member

  • Member
  • PipPip
  • 206 posts
  • Joined 16-July 06
i've looked at the Win32_NetworkAdapterConfiguration WMI class, and nothing there is useful.

(the DNSDomain and DNSHostName properties sound promising but aren't)

i can get the information from the registry, but that's a last resort.

anyone know how to get the DNS server (like is displayed on Status -> Support -> Details on your current connection) through WMI or another API?

Edited by #rootworm, 17 May 2007 - 05:42 AM.

bpx messageboxa


How to remove advertisement from MSFN

#2
jondercik

jondercik

    Advanced Member

  • Member
  • PipPipPip
  • 445 posts
  • Joined 15-January 04
Any of the code samples on the following link help?

http://www.activexpe...working/client/
Jim
R.I.P. Alienware
1996-2006

#3
#rootworm

#rootworm

    Member

  • Member
  • PipPip
  • 206 posts
  • Joined 16-July 06
it doesn't look like it, but thanks.

i thought it would be quick and easy to get this info, but it's tucked away somewhere.
bpx messageboxa

#4
jondercik

jondercik

    Advanced Member

  • Member
  • PipPipPip
  • 445 posts
  • Joined 15-January 04
 
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration")
For Each objItem in colItems
Wscript.Echo "ARP Always Source Route: " & objItem.ArpAlwaysSourceRoute
Wscript.Echo "ARP Use EtherSNAP: " & objItem.ArpUseEtherSNAP
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "Database Path: " & objItem.DatabasePath
Wscript.Echo "Dead GW Detection Enabled: " & objItem.DeadGWDetectEnabled
Wscript.Echo "Default IP Gateway: " & objItem.DefaultIPGateway
Wscript.Echo "Default TOS: " & objItem.DefaultTOS
Wscript.Echo "Default TTL: " & objItem.DefaultTTL
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "DHCP Enabled: " & objItem.DHCPEnabled
Wscript.Echo "DHCP Lease Expires: " & objItem.DHCPLeaseExpires
Wscript.Echo "DHCP Lease Obtained: " & objItem.DHCPLeaseObtained
Wscript.Echo "DHCP Server: " & objItem.DHCPServer
Wscript.Echo "DNS Domain: " & objItem.DNSDomain
Wscript.Echo "DNS Domain Suffix Search Order: " & _
objItem.DNSDomainSuffixSearchOrder
Wscript.Echo "DNS Enabled For WINS Resolution: " & _
objItem.DNSEnabledForWINSResolution
Wscript.Echo "DNS Host Name: " & objItem.DNSHostName
Wscript.Echo "DNS Server Search Order: " & objItem.DNSServerSearchOrder
Wscript.Echo "Domain DNS Registration Enabled: " & _
objItem.DomainDNSRegistrationEnabled
Wscript.Echo "Forward Buffer Memory: " & objItem.ForwardBufferMemory
Wscript.Echo "Full DNS Registration Enabled: " & _
objItem.FullDNSRegistrationEnabled
Wscript.Echo "Gateway Cost Metric: " & objItem.GatewayCostMetric
Wscript.Echo "IGMP Level: " & objItem.IGMPLevel
Wscript.Echo "Index: " & objItem.Index
Wscript.Echo "IP Address: " & objItem.IPAddress
Wscript.Echo "IP Connection Metric: " & objItem.IPConnectionMetric
Wscript.Echo "IP Enabled: " & objItem.IPEnabled
Wscript.Echo "IP Filter Security Enabled: " & _
objItem.IPFilterSecurityEnabled
Wscript.Echo "IP Port Security Enabled: " & _
objItem.IPPortSecurityEnabled
Wscript.Echo "IPSec Permit IP Protocols: " & _
objItem.IPSecPermitIPProtocols
Wscript.Echo "IPSec Permit TCP Ports: " & objItem.IPSecPermitTCPPorts
Wscript.Echo "IPSec Permit UDP Ports: " & objItem.IPSecPermitUDPPorts
Wscript.Echo "IP Subnet: " & objItem.IPSubnet
Wscript.Echo "IP Use Zero Broadcast: " & objItem.IPUseZeroBroadcast
Wscript.Echo "IPX Address: " & objItem.IPXAddress
Wscript.Echo "IPX Enabled: " & objItem.IPXEnabled
Wscript.Echo "IPX Frame Type: " & objItem.IPXFrameType
Wscript.Echo "IPX Media Type: " & objItem.IPXMediaType
Wscript.Echo "IPX Network Number: " & objItem.IPXNetworkNumber
Wscript.Echo "IPX Virtual Net Number: " & objItem.IPXVirtualNetNumber
Wscript.Echo "Keep Alive Interval: " & objItem.KeepAliveInterval
Wscript.Echo "Keep Alive Time: " & objItem.KeepAliveTime
Wscript.Echo "MAC Address: " & objItem.MACAddress
Wscript.Echo "MTU: " & objItem.MTU
Wscript.Echo "Number of Forward Packets: " & objItem.NumForwardPackets
Wscript.Echo "PMTUBH Detect Enabled: " & objItem.PMTUBHDetectEnabled
Wscript.Echo "PMTU Discovery Enabled: " & objItem.PMTUDiscoveryEnabled
Wscript.Echo "Service Name: " & objItem.ServiceName
Wscript.Echo "Setting ID: " & objItem.SettingID
Wscript.Echo "TCPIP Netbios Options: " & objItem.TcpipNetbiosOptions
Wscript.Echo "TCP Maximum Connect Retransmissions: " & _
objItem.TcpMaxConnectRetransmissions
Wscript.Echo "TCP Maximum Data Retransmissions: " & _
objItem.TcpMaxDataRetransmissions
Wscript.Echo "TCP NumC onnections: " & objItem.TcpNumConnections
Wscript.Echo "TCP Use RFC1122 Urgent Pointer: " & _
objItem.TcpUseRFC1122UrgentPointer
Wscript.Echo "TCP Window Size: " & objItem.TcpWindowSize
Wscript.Echo "WINS Enable LMHosts Lookup: " & _
objItem.WINSEnableLMHostsLookup
Wscript.Echo "WINS Host Lookup File: " & objItem.WINSHostLookupFile
Wscript.Echo "WINS Primary Server: " & objItem.WINSPrimaryServer
Wscript.Echo "WINS Scope ID: " & objItem.WINSScopeID
Wscript.Echo "WINS Secondary Server: " & objItem.WINSSecondaryServer
Next


Jim
R.I.P. Alienware
1996-2006

#5
#rootworm

#rootworm

    Member

  • Member
  • PipPip
  • 206 posts
  • Joined 16-July 06
which of those was supposed to tell me my DNS server?

Edited by #rootworm, 17 May 2007 - 07:38 AM.

bpx messageboxa

#6
jondercik

jondercik

    Advanced Member

  • Member
  • PipPipPip
  • 445 posts
  • Joined 15-January 04
Wscript.Echo "DNS Server Search Order: " & objItem.DNSServerSearchOrder
Jim
R.I.P. Alienware
1996-2006

#7
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,421 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
Here is a shorter version of the above script.

strComputer = "." 
 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
 Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration",,48) 
  For Each objItem in colItems 
   If Not IsNull(objItem.DNSHostName) Then 
	A = Space(5) & "Win32_Network Adapter Configuration Instance"  & vbCrLf &_  
		"---------------------------------------------------------" & vbCrLf &_
		" DNS Host Name" & Space(31) & " : " & objItem.DNSHostName & vbCrLf &_
		" DNS Server Search Order" & Space(17) & " : " & Join(objItem.DNSServerSearchOrder, ",") & vbCrLf &_
		" Domain DNS Registration Enabled : " & objItem.DomainDNSRegistrationEnabled & vbCrLf &_
		"---------------------------------------------------------"
   End If 
  Next
 MsgBox A,4128,"Adapter Info"




GunSmokingMan



#8
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,557 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

gsm, why all the spaces? would it not be neater using tabs?
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration",,48)
For Each objItem in colItems
If Not IsNull(objItem.DNSHostName) Then
A = Space(4) & "Win32_Network Adapter Configuration Instance" & vbCrLf &_
"----------------------------------------------------------------" & vbCrLf &_
" DNS Host Name :" & vbTab & vbTab & vbTab & objItem.DNSHostName & vbCrLf &_
" DNS Server Search Order :" & vbTab & vbTab & Join(objItem.DNSServerSearchOrder, ",") & vbCrLf &_
" Domain DNS Registration Enabled :" & vbTab & objItem.DomainDNSRegistrationEnabled & vbCrLf &_
"----------------------------------------------------------------"
End If
Next
MsgBox A,4128,"Adapter Info"


#9
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,421 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag

gsm, why all the spaces? would it not be neater using tabs?

strComputer = "."Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration",,48)	For Each objItem in colItems		If Not IsNull(objItem.DNSHostName) Then			A = Space(4) & "Win32_Network Adapter Configuration Instance"  & vbCrLf &_  			"----------------------------------------------------------------" & vbCrLf &_			" DNS Host Name :" & vbTab & vbTab & vbTab & objItem.DNSHostName & vbCrLf &_			" DNS Server Search Order :" & vbTab & vbTab & Join(objItem.DNSServerSearchOrder, ",") & vbCrLf &_			" Domain DNS Registration Enabled :" & vbTab & objItem.DomainDNSRegistrationEnabled & vbCrLf &_			"----------------------------------------------------------------"		End If	NextMsgBox A,4128,"Adapter Info"

On Vista the tabs would not line up correct. So I just used the space to line them up.

Edited by gunsmokingman, 17 May 2007 - 01:23 PM.



GunSmokingMan



#10
#rootworm

#rootworm

    Member

  • Member
  • PipPip
  • 206 posts
  • Joined 16-July 06
haha, thanks jondercik!! i can't believe i missed that. well, okay...i can. i was more than a little tired when i was trying to figure this out. thanks for babying me and telling me the exact property i needed ;)

here's the code i ended up using in C#:

ManagementClass MC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection MOC = MC.GetInstances();

foreach (ManagementObject MO in MOC)
			{
				if ((bool)MO["ipEnabled"] && MO["DNSHostName"] != null)
				{
					string[] DNS = (string[])MO["DNSServerSearchOrder"];
					...
				}
			}

Edited by #rootworm, 17 May 2007 - 04:30 PM.

bpx messageboxa




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users