IP Address lookup problem

C

Code Monkey

Hope someone can help me out here.


I'm writing some code (web forms) to see where a specific domain name
resolves and if its not a local address, redirect to a specific
redirect page.


<code>
IPHostEntry IPHost = Dns.Resolve("www.domainname.com");
IPAddress[] addr = IPHost.AddressList;
for (int i = 0;i < addr.Length;i++)
{
Response.Write(addr + "<br/>");


}


</code>

That code works fine.
Now, local IP addresses are:


10.0.0.0 - 10.255.255.255
172.16.0.0 - 172.31.0.0
192.168.0.0 - 192.168.255.0


is there a built in function in C# that's effectively a
'isLocalIPaddress()' ? Or do I have to code this the long way round on
each individual octect of the given IP of the domain name?
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

What you mean with local address? it's an IP in the same computer?

in anycase there is not, you will have to generate a list of local ips, and
then use the AddressList to compare with it.

now, if www.domainname.com does not change you can do it once in the
global.asasx app_init method and store it either in Application or in a
static variable


cheers,
 
C

Code Monkey

Local IP addresses: ie; a domain name located on the same (internal)
network, either on the same machine, or another machine.

ie; 3 servers on the same internal network(s) dealing, each machine has
a domain name exposed to the web, www.domain-a.com, www.domain-c.com,
www.domain-c.com.

and the local IP addresses could be 10.0.0.100, 192.168.0.101 and
172.16.0.102

A web page is created, which has a redirect (such as an advert managed
from a CMS) on it. If the redirect from www.domain-a.com is going to
www.domain-b.com, no warning is going to be shown - we have control
over the content.

However, if the redirect is going to www.yahoo.com (just an example), a
warning would be shown such as 'you are leaving our site, we have no
guarantee of the content of this othersite'.

so, any domain name which can be resolved locally and produces an IP
address within the range of my previous post, does not produce the
warning, but an IP address which is obviously external to our DNS
server, would produce the warning on the redirection page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top