473,385 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

IP Address lookup problem

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[i] + "<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?

Nov 17 '05 #1
2 1873
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Code Monkey" <dl********@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
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[i] + "<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?

Nov 17 '05 #2
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.

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Darren Kirby | last post by:
Hello list: I am writing a small app in python which tracks the kernel banner at kernel.org and downloads newer kernel version(s) (if there are any). I am using GeoIP to set the download to a...
2
by: CoreyWhite | last post by:
The future of computer architecture will use lookup tables. Currently computer processor speed outweighs the benefits of using computer memory for lookup tables, except in some cases. As computer...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
0
by: 143.182.124.4 [Shameer Balasingam] | last post by:
There is a database to lookup all IP address space to country. Pretty cool... I've used it for my web application and I believe it can be used by C too. http://www.location.com.my/products.asp...
5
by: Horst Walter | last post by:
What is wrong here? IPAddress ipAddress = IPAddress.Parse("10.10.20.1"); IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, this.port); this.tcpClient = new TcpClient(ipEndPoint); // PROBLEM HERE...
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
3
by: Radu | last post by:
Hi. I have the following problem - I need to build a user-control in asp.net (an ascx) to somehow allow the users to search by first name or last name among a big (~10.000 records) email addresses...
1
by: paulquinlan100 | last post by:
Hi Im having problems getting a column in one of my tables to display the lookup values correctly. The database is split, in the backend the rowsource for this particular field is set to a...
7
by: Chris Morley | last post by:
Hi, i have found out as i have developed the database i've ended up with a number of tables that have the same attributes. For instance, my suppliers and customers have the same fields for the...
2
by: r0g | last post by:
Not the visitors IP address, or rdns, indeed they seem to be getting in the way of my googling for the answer despite qualifying my searches with -reverse and -remote_addr No, what I need is a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.