1

I'm writing a program that is accessed from a local network and also from the outside. I have to identify local and outside requests in order to give different functionality to each. Is that possible? An alternative is to document the IP addresses of all the local computers and to get the IP address of the client thru Request.ServerVariables["Remote_ADDRS"] and compare them, if the request IP address doesn't match that means the request is not local. That seems to be awkward and inefficient because I would have to save all local addresses and any new computer would have to be regestered. Is there a simple way to identify if a request is coming from the local network or from the outside? Thank you!

Dov Miller
  • 1,958
  • 5
  • 34
  • 46

2 Answers2

1

Your network administrator will be able to tell you the IP range of the internal network. Then you can simply check if the client IP falls into the internal range.

This way, you only need to change your configuration, when the internal ranges is changed. This should not happen too often.

Edit: Here is a question and answer about IP ranges (albeit in Java, but should be very simple to convert).

Community
  • 1
  • 1
driis
  • 161,458
  • 45
  • 265
  • 341
  • Wouldn't internal networks requests be all in the 192.168.x.x ? – Haedrian Nov 20 '11 at 11:07
  • Internal network can be of class A, B (16 continuous subs) or C (256 continuous subs). 192.168.x.x is class C network and has range for 65K addresses only. – Valery Nov 20 '11 at 11:14
  • @driis Thank you that's what I need. I understand that the IP is a string, how do I check if the user IP falls in range of strings? – Dov Miller Nov 20 '11 at 13:38
  • The IP is often represented as a string, but in reality it's just 4 bytes (for IPv4). It depends on what range you actually get, but for simple networks, it will often be a matter of checking if the first 1 - 3 bytes matches, depending on what range you are given - or you can just make a 32 bit integer out of the 4 bytes and compare to the range you are given. – driis Nov 20 '11 at 14:24
  • @driis Thank you for the link, but I don't know how to make the conversion. I'd appreciate help on that. – Dov Miller Nov 21 '11 at 12:09
  • I found the following link for the conversion in c#: [How to convert an IPv4 address into a integer in C#?](http://stackoverflow.com/questions/461742/how-to-convert-an-ipv4-address-into-a-integer-in-c) – Dov Miller Nov 21 '11 at 12:48
0

Are you on a domain with the internal users? If so you could just offer the internal functionality only to those who login with integrated authentication.

Brandon Moore
  • 8,590
  • 15
  • 65
  • 120