#rootworm Posted May 17, 2007 Posted May 17, 2007 (edited) 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 May 17, 2007 by #rootworm
jondercik Posted May 17, 2007 Posted May 17, 2007 Any of the code samples on the following link help?http://www.activexperts.com/activmonitor/w...working/client/
#rootworm Posted May 17, 2007 Author Posted May 17, 2007 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.
jondercik Posted May 17, 2007 Posted May 17, 2007 On Error Resume NextstrComputer = "."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.WINSSecondaryServerNext
#rootworm Posted May 17, 2007 Author Posted May 17, 2007 (edited) which of those was supposed to tell me my DNS server? Edited May 17, 2007 by #rootworm
jondercik Posted May 17, 2007 Posted May 17, 2007 Wscript.Echo "DNS Server Search Order: " & objItem.DNSServerSearchOrder
gunsmokingman Posted May 17, 2007 Posted May 17, 2007 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"
Yzöwl Posted May 17, 2007 Posted May 17, 2007 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"
gunsmokingman Posted May 17, 2007 Posted May 17, 2007 (edited) 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 May 17, 2007 by gunsmokingman
#rootworm Posted May 17, 2007 Author Posted May 17, 2007 (edited) 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 May 17, 2007 by #rootworm
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now