How to get an IP from a domain name in ASP.NET
The case is as follows. We want to connect to machines behind us of a connection with dynamic IP and use the old trick of the domains in DynDns.org or similar services.
Every time we want to know the IP then we MiDominio.dyndns.org ping or whatever and that's it.
And if we do a little more pituco?
Imports System.Net.NetworkInformation
The Page_Load method of an ASP.NET page write (in VB.NET): Dim
hostInfo Dns.GetHostByName As IPHostEntry = ( "MiDominio.dyndns.org") Label1.Text = hostInfo.AddressList
(0). ToString
and we will happily IP Label1 we seek.
AddressList Mindful that is actually a settlement and eventually could get several IPs. for that case we should use a For Each to list them all.
Another way is to use the Ping object: Dim
oping System.Net.NetworkInformation.Ping As Ping = New () Dim reply As
Oping.Send PingReply = ("www.google.com")
Label2.Text =
reply.Address.ToString
But sometimes we can get exceptions to the test sites with no pingueables. In such cases better use DNS object.
0 comments:
Post a Comment