Grab IP of local machine, and display code based on the ip range they are in - ASP

I manage an intranet for two remote sites - both sites need to have identical file names and folder structures.

I have location A's web server at 192.168.1.10.  All of location A is on subnet 192.168.1.x

I have location B's web server at 192.168.2.10.  All of location B is on subnet 192.168.2.x

What I would like to do is create a web page with specific information for that site, such as weather and events.  I want to detect the ip address of the machine so that the page displays the appropriate code for that site.

so the asp code would grab the ip, and say if the ip matches a sepcific subnet, display the data for that site.  Else, display the data for the other site. In very basic terms:

if ip address = 192.168.1.x range then

<html code>

else if ip address = 192.168.2.x range then

<html code>

else

<html code>

end if

any ideas?

Thanks!
tabascoman27Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jmelikaCommented:
Hello,

Request.ServerVariable("LOCAL_ADDR") will give you the IP address of the web server.

Have fun!

JM
0
wesbirdCommented:
This should answer it:

<head>
</head>
<body>
<p>Server IP: <% Response.write Request.ServerVariables ("LOCAL_ADDR") %> </p>

<p>Client IP: <% Response.write Request.ServerVariables("REMOTE_ADDR") %> </p>
</body>


Wes
0
wesbirdCommented:
<body>
<p>Server IP: <% Response.write Request.ServerVariables ("LOCAL_ADDR") %> </p>
<p>Client IP: <% Response.write Request.ServerVariables("REMOTE_ADDR") %> </p>
<p>
<%
      strArr = split( Request.ServerVariables("REMOTE_ADDR"), "." )
      if strArr(2) = "1" then
            Response.Write "Subnet 192.168.1.x"
      else
            Response.Write "Subnet 192.168.2.x"
      end if
%>
</p>
</body>
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

jmelikaCommented:
I don't personally think it's a good system to use IF in this case.  It would be better with a SELECT CASE.

<%
Select Case Request.ServerVariable("LOCAL_ADDR")
  Case "192.168.1.10"
    'Do the code of Server A
  Case "192.168.2.10"
    'Do the code of Server B
  Case Else
    'Display the result of unexpected IP address
End Select
%>

This is a better identification of the likely cases.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wesbirdCommented:
jmelika,

We're splitting hairs here - the fact is that it is Request.ServerVariables("REMOTE_ADDR") has the IP address.  We could do:

<body>
<p>Server IP: <% Response.write Request.ServerVariables ("LOCAL_ADDR") %> </p>
<p>Client IP: <% Response.write Request.ServerVariables("REMOTE_ADDR") %> </p>
<p>
<%
  select case strArr(2)
       ' ...etc would be more sensible
%>
</p>
</body>

instead.  

I'd like to wait until tabascoman27 responds please.

Cheers

Wes


0
wesbirdCommented:
Ooops,

plus this line from above again (P.S. jmelika is is still refering to the server IP address instead of the client one)

     strArr = split( Request.ServerVariables("REMOTE_ADDR"), "." )
0
jmelikaCommented:
wesbird, nice catch.  I was thinking of server's IP address because he mentioned that each site has its own server.
0
tabascoman27Author Commented:
Thank you for the quick responses!  I will try all today, and see what happens.  
0
tabascoman27Author Commented:
Well, I'm going to accept jmelika's answer.   Case worked great, and using the server variable actually works perfectly.   A laptop user from office A might come to office B to visit , but will still be pointed to his office A web server, and would still still want to see his home location's info for events, news, etc.  He'll still pick up the local DHCP address from the local subnet in office B, but still need to have office A's information.  Doing things this way also gives the opprotunity to visit the other site's web server and get information on that site while keeping the coding simple for me.

I'm going to split some points over to wesbird for an assisted answer because I might still that code somewhere else.

I have to say thank you for the quick responses, I very much appreciate it.


0
wesbirdCommented:
looks like the the split went wrong!
0
tabascoman27Author Commented:
Ah!  Sorry about that.  Clicked too fast.  I put a request in the community forum to have the question reopened so I can split.
0
tabascoman27Author Commented:
Increased Points
0
wesbirdCommented:
Thankyou
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.