Magnus R,
You have a couple options.
You could use PInvoke for the following signature:
Private Declare Function NetGetDCName Lib "netapi32.d ll" (ByVal
strServerName As Object, ByVal strDomainName As Object, ByVal pBuffer As
Long) As Long
You could use the System.Net namespace:
Dim MYIP As System.Net.IPHo stEntry =
System.Net.Dns. GetHostEntry(My .Computer.Name)
Dim IPaddress As String = MYIP.AddressLis t.GetValue(0).T oString
Console.WriteLi ne(System.Net.D ns.GetHostEntry (IPaddress).Hos tName)
You could also use the System.Net.Netw orkInformation namespace for the long
way around, but more detail. Check out this code:
Imports System.Net
Imports System.Net.Netw orkInformation
Public Class NetworkInfo
Public Shared Sub ShowIPAddresses ()
Dim computerPropert ies As IPGlobalPropert ies =
IPGlobalPropert ies.GetIPGlobal Properties()
Dim nics() As NetworkInterfac e =
NetworkInterfac e.GetAllNetwork Interfaces()
Console.WriteLi ne("Interface information for {0}.{1} ", _
computerPropert ies.HostName, computerPropert ies.DomainName)
If (nics Is Nothing OrElse nics.Length < 1) Then
Console.WriteLi ne(" No network interfaces found.")
Return
End If
Console.WriteLi ne(" Number of interfaces ............... ..... :
{0}", nics.Length)
For Each adapter As NetworkInterfac e In nics
Dim adapterProperti es As IPInterfaceProp erties =
adapter.GetIPPr operties()
Dim dnsServers As IPAddressCollec tion =
adapterProperti es.DnsAddresses
If (Not dnsServers Is Nothing) Then
For Each dns As IPAddress In dnsServers
Console.WriteLi ne(" DNS Servers
............... ............... : {0}", dns.ToString())
Console.WriteLi ne(" Server Name
............... ............ : {0}",
System.Net.Dns. GetHostEntry(dn s.ToString).Hos tName)
Next
End If
Next
End Sub
End Class
You could also use the registry:
http://www.java2s.com/Code/CSharp/Ne...DNSServers.htm
Hope this helps,
Steve
"Magnus R" <ro******@hotma il.comwrote in message
news:e5******** ******@TK2MSFTN GP04.phx.gbl...
>I am using the System.Net namespace to do DNS lookups of a host and return
their IP address. However I haven't figured out how to use the namespace to
take a domain name and find the responsible nameservers. Does anyone have
an idea how to do this?