[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Getting users location via IP Address

Posted on 2011-10-27
14
Medium Priority
?
323 Views
Last Modified: 2012-05-12
I work for a company where most of our employees are on the road travelling around the country during the day.  They  have access to our corporate intranet where they use a cell companies air card to VPN into our network to access our intranet.

On the home page of our intranet, I want to put weather and traffic information for the reps.  I would like this to switch dynamically based on the city that the employee is in.

The problem is when I get the reps IP address, it's showing an internal IP, since they are using the VPN.

Is there a way that I can get the aircard's IP address without the VPN address to make this happen, or is there another way I can go about getting their location on the fly without needing an IP?

Thank you.
0
Comment
Question by:t3chguy
  • 4
  • 4
  • 3
  • +2
14 Comments
 
LVL 13

Expert Comment

by:IT-Monkey-Dave
ID: 37039855
Hmm, I'm thinking the only place you would be able to get their public IP from is the VPN log file(s).  It's most likely recording that data (if it isn't it should be).

I can't think of any other way to pinpoint their location...
0
 
LVL 10

Expert Comment

by:effx
ID: 37039935
You could use HTML5 Location services
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 37040613
Try having one of your reps VPN and run this script, then bring you the output.  If you look near the bottom all the available information will be there.
<?php phpinfo();

Open in new window


If you can get an IP address that tells the location, you can translate it with something like the design pattern shown in this article.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_3437-IP-Address-to-Country-in-PHP.html

If you cannot get an IP address, you might ask the rep to enter the nearest ZIP code.   Then you can use the Google Weather API.  In the example, $z is the 5-digit ZIP code.

HTH, ~Ray
// GOOGLE WEATHER WIDGET IS SOMETIMES SLOW
$url = "http://www.google.com/ig/api?weather=$z";
if ($xml = curl_get($url))
{
    $obj = SimpleXML_Load_String($xml);

    // EXTRACT AND FORMAT THE DATA
    $t = $obj->weather->forecast_information->city["data"];
    $d = $obj->weather->forecast_information->current_date_time["data"];
    $d = date('g:ia', strtotime($d));
    $s = $obj->weather->current_conditions->condition["data"];
    $f = $obj->weather->current_conditions->temp_f["data"];
    $h = $obj->weather->current_conditions->humidity["data"];

    $weather_lnk = "<span class=\"weather\">$s, $f&#176;F, $h <br/>at $d in $t</span>" . PHP_EOL;
}

Open in new window

0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 10

Expert Comment

by:effx
ID: 37041042
@Ray, once again you amaze me with how you got your status on EE. VPN's make users seem like they are on the internal network, internet routing would go through the internal modem, thus advertising to the websites that the VPN client is visiting that the client is at the office irrespecteve of thier location. HTML5 GeoLocation should work based on the mobile devices internal GPS with a fallback to IP location this will give you the most accurate location detection of the remote device on the VPN.

On another note, can the user just look out of a window to see if its raining :)

0
 
LVL 10

Expert Comment

by:ukerandi
ID: 37043677
down vote  Try the following -
$_SERVER['HTTP_X_FORWARDED_FOR']; // in place of REMOTE_ADDR  You can also try referencing SERVER_NAME using:

$_SERVER['HTTP_X_FORWARDED_HOST'];  $_SERVER['HTTP_X_FORWARDED_SERVER'];

i'm not sure but worh to check
As far as i knew,Whatever PHP (rather the web server) returns is the address that the request was made from. There's no way for the script to know if you're behind a VPN or proxy.
0
 
LVL 13

Expert Comment

by:IT-Monkey-Dave
ID: 37046071
Could you somehow change the VPN connection process (client side) to record the user's real IP address prior to initiating the VPN each time.  Or maybe the real IP is being logged by the VPN client and you can extract the data from the log.
0
 
LVL 1

Author Comment

by:t3chguy
ID: 37046091
The problem with the VPN connection is that the air cards change IP addresses frequently.  I've been watching the log to see if by chance the users typically get the same two or three IPs so I can just use OR statements in the query to get their location.

0
 
LVL 13

Expert Comment

by:IT-Monkey-Dave
ID: 37046121
I would think that the IP used by the air cards will not be a reliable indicator of the user's geographic location.  The way cell systems work, the IP could be coming from just about anywhere.  I'm not an expert but I doubt you can rely on the air card's public IP, even if you can get it.
0
 
LVL 1

Author Comment

by:t3chguy
ID: 37046139
So you think the best way to go is HTML5 Location services as suggested above or else just having the user maintain their own zip code for where they want to get weather, traffic information from?
0
 
LVL 13

Expert Comment

by:IT-Monkey-Dave
ID: 37046150
Sorry, I don't know anything about HTML5 so can't help with that.  ZIP code, if you can get the user to enter it, would always work.
0
 
LVL 1

Author Comment

by:t3chguy
ID: 37046159
I don't like the HTML5 location services as it is really slow.  Thank you for the suggestions!
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 37047726
One last comment then I will sign off on this question.  If you look at the code snippet posted at ID:37040613 You will see a call to a local function, curl_get().  Logically that function does the same thing as file_get_contents(), however it enables the script to disconnect after two seconds.  If you want to use the Google widget, it's necessary to know that it is not always very quick to respond.  For that reason, I did not use file_get_contents() -- I did not want to keep the site hanging while waiting on an outside service that produces non-critical information.

You can see the information from that script on this page.  Look in the right sidebar at the bottom.
http://www.landonbaseball.com/

Best to all, over and out, ~Ray
0
 
LVL 10

Expert Comment

by:effx
ID: 37048123
What devices are you using?
0
 
LVL 1

Author Comment

by:t3chguy
ID: 37048133
For now just a laptop. I'll eventually move to mobile applications but the bulk of our users are on laptops connecting through vpn with Verizon and at&t aircards.
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to fix a SonicWall Gateway Anti-Virus firewall blocking automatic updates to apps like Windows, Adobe, Symantec, etc.
This article will show you step-by-step instructions to build your own NTP CentOS server.  The network diagram shows the best practice to setup the NTP server farm for redundancy.  This article also serves as your NTP server documentation.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question