.NET Framework - System.Net.Dns????
Asked By Brian
12-Oct-08 11:05 PM
Hi.. I don't get it.... this procedure is obsolete.. that is obsolete....
I am trying to rewrite a program i wrote in vb 6 years ago
Dim hostIPAddress As IPAddress = IPAddress.Parse(Me.txtLookupHostIP.Text)
Dim hostinfo As IPHostEntry =
System.Net.Dns.GetHostEntry(hostIPAddress.ToString)
?system.Net.Dns.Resolve(hostIPAddress.ToString)
{System.Net.IPHostEntry}
AddressList: {Length=1}
Aliases: {Length=0}
HostName: "ComputerName.DomainName"
?System.Net.Dns.GetHostEntry(hostIPAddress.ToString)
Run-time exception thrown : System.Net.Sockets.SocketException - No such
host is known
warnings say not to use resolve, but to use GetHostEntry
I am just trying to pass an IP address and get the Host name... either from
the internet or local network.. or pass the host name and get the ip..
System.Net.Dns.GetHostEntry
(1)
System.Net.IPHostEntry
(1)
IPHostEntry
(1)
ComputerName.DomainName
(1)
IPAddress.Parse
(1)
IPAddress
(1)
Vb 6
(1)
SocketException
(1)
kimiraikkonen replied...
om
Using VB 2005, i can get hostname simply by using:
System.Net.Dns.GetHostName.ToString
And getting IP address by passing hostname can be done using:
'-----------------------------------
Imports System.Net.Dns
Imports System.Net
Dim hostname As String
hostname =3D GetHostName.ToString
For Each ip As IPAddress In _
GetHostEntry(hostname).AddressList
' Return IP address in messagebox
MsgBox(ip.ToString)
Next
'------------------------------
Hope this helps,
Onur G=FCzel
Brian replied...
ok, now what about passing an ip address?
MsgBox(GetHostEntry(Me.txtLookupHostIP.Text).HostName)
me.txtLookupHostIP.text = 192.168.1.1 This address is assigned from a dhcp
server on the local network....
and is listed in the dns.. and I get "No such host is known"
Using VB 2005, i can get hostname simply by using:
System.Net.Dns.GetHostName.ToString
And getting IP address by passing hostname can be done using:
'-----------------------------------
Imports System.Net.Dns
Imports System.Net
Dim hostname As String
hostname = GetHostName.ToString
For Each ip As IPAddress In _
GetHostEntry(hostname).AddressList
' Return IP address in messagebox
MsgBox(ip.ToString)
Next
'------------------------------
Hope this helps,
Onur Güzel
kimiraikkonen replied...
a dhcp
Well, it seems you want to get host name by passing an IP address and
that can be done using:
Imports System.Net.Dns
' Your computer's LAN IP address
' assigned by your router or LAN device
Dim ip As String =3D "192.168.1.2"
' that returns my hostname
MsgBox(GetHostEntry(ip).HostName.ToString)
Note: You must pay attention to your firewall installed on your
machine, which may prevent you from retrieving info about your IP
address, and may require to set "trusted" rule or similar manually.
Plus make sure, you're passing correct IP address.
Hope this helps,
Onur G=FCzel
http: / / msdn.microsoft.com / en-us / library / system.net.dns_members.aspx The recommended alternative is [System.Net.Dns]::GetHostEntry() em.net.dns_members.aspx = A0The Kuma: Thanks for this information. Could you possibly help me work: $hostname_Y.computername but this will: $hostname_Y.hostname Also, no "IPAddressToString" method is provided for [System.Net.Dns]::GetHostEntry() as is provided for [System.Net.IPAddress] [System.Net.IPAddress]::Broadcast.IPAddressToString or [System.Net
192.168.0.5 \ temp I tried to resolve the IPAddress to a name using System.Net.Dns.GetHostEntry but just get an exception "No such host is known". Is there a way around connect to the PC by \ ipaddress \ share . / / Resolve the IP Address to a host name System.Net.IPHostEntry aIPHE = System.Net.Dns.GetHostEntry("192.168.0.12"); / / Show the result this.lblHostName.Text = aIPHE.HostName
14:56, schrieb Roidy: Try this: (passing "NAS") System.Net.Dns.GetHostByName(ByVal String) As System.Net.IPHostEntry Does it fail, too? - - Armin Thanks Armin, VB complains that GetHostByName is obsolete and tells you to use GetHostEntry, which works perfectly:- Dim hostname As System.Net.IPHostEntry System.Net.Dns.GetHostEntry("NAS") Dim ipaddress() As System.Net.IPAddress = hostname.AddressList Now it just an
pBuffer As Long) As Long You could use the System.Net namespace: Dim MYIP As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(My.Computer.Name) Dim IPaddress As String = MYIP.AddressList.GetValue(0).ToString Console.WriteLine(System.Net.Dns.GetHostEntry(IPaddress).HostName) You could also use the System.Net.NetworkInformation namespace for