Rectangle 27 320

I would use a web service that can return JSON (along with jQuery to make things simpler). Below are all the free active IP lookup services I could find and the information they return. If you know of any more, then please add a comment and I'll update this answer.

{
  "address": "116.12.250.1",
  "country": "SG",
  "stateprov": "Central Singapore",
  "city": "Singapore"
}
{
  "ip": "116.12.250.1",
  "country_code": "SG",
  "country_name": "Singapore",
  "region_code": "01",
  "region_name": "Central Singapore Community Development Council",
  "city": "Singapore",
  "zip_code": "",
  "time_zone": "Asia/Singapore",
  "latitude": 1.2931,
  "longitude": 103.8558,
  "metro_code": 0
}
$.getJSON('http://gd.geobytes.com/GetCityDetails?callback=?', function(data) {
  console.log(JSON.stringify(data, null, 2));
});
{
  "geobytesforwarderfor": "",
  "geobytesremoteip": "116.12.250.1",
  "geobytesipaddress": "116.12.250.1",
  "geobytescertainty": "99",
  "geobytesinternet": "SA",
  "geobytescountry": "Saudi Arabia",
  "geobytesregionlocationcode": "SASH",
  "geobytesregion": "Ash Sharqiyah",
  "geobytescode": "SH",
  "geobyteslocationcode": "SASHJUBA",
  "geobytescity": "Jubail",
  "geobytescityid": "13793",
  "geobytesfqcn": "Jubail, SH, Saudi Arabia",
  "geobyteslatitude": "27.004999",
  "geobyteslongitude": "49.660999",
  "geobytescapital": "Riyadh ",
  "geobytestimezone": "+03:00",
  "geobytesnationalitysingular": "Saudi Arabian ",
  "geobytespopulation": "22757092",
  "geobytesnationalityplural": "Saudis",
  "geobytesmapreference": "Middle East ",
  "geobytescurrency": "Saudi Riyal",
  "geobytescurrencycode": "SAR",
  "geobytestitle": "Saudi Arabia"
}
  • Can return the wrong location (I'm in Singapore, not Saudi Arabia)
$.getJSON('http://www.geoplugin.net/json.gp?jsoncallback=?', function(data) {
  console.log(JSON.stringify(data, null, 2));
});
{
  "geoplugin_request": "116.12.250.1",
  "geoplugin_status": 200,
  "geoplugin_credit": "Some of the returned data includes GeoLite data created by MaxMind, available from <a href=\\'http://www.maxmind.com\\'>http://www.maxmind.com</a>.",
  "geoplugin_city": "Singapore",
  "geoplugin_region": "Singapore (general)",
  "geoplugin_areaCode": "0",
  "geoplugin_dmaCode": "0",
  "geoplugin_countryCode": "SG",
  "geoplugin_countryName": "Singapore",
  "geoplugin_continentCode": "AS",
  "geoplugin_latitude": "1.2931",
  "geoplugin_longitude": "103.855797",
  "geoplugin_regionCode": "00",
  "geoplugin_regionName": "Singapore (general)",
  "geoplugin_currencyCode": "SGD",
  "geoplugin_currencySymbol": "&#36;",
  "geoplugin_currencySymbol_UTF8": "$",
  "geoplugin_currencyConverter": 1.4239
}
IP Address: 116.12.250.1
Country: SG
State: N/A
City: Singapore
Latitude: 1.293100
Longitude: 103.855797
$.getJSON('//ipapi.co/json/', function(data) {
  console.log(JSON.stringify(data, null, 2));
});
{
  "ip": "116.12.250.1",
  "city": "Singapore",
  "region": "Central Singapore Community Development Council",
  "country": "SG",
  "country_name": "Singapore",
  "postal": null,
  "latitude": 1.2855,
  "longitude": 103.8565,
  "timezone": "Asia/Singapore"
}
$.getJSON('http://ip-api.com/json?callback=?', function(data) {
  console.log(JSON.stringify(data, null, 2));
});
{
  "as": "AS3758 SingNet",
  "city": "Singapore",
  "country": "Singapore",
  "countryCode": "SG",
  "isp": "SingNet Pte Ltd",
  "lat": 1.2931,
  "lon": 103.8558,
  "org": "Singapore Telecommunications",
  "query": "116.12.250.1",
  "region": "01",
  "regionName": "Central Singapore Community Development Council",
  "status": "success",
  "timezone": "Asia/Singapore",
  "zip": ""
}
$.getJSON('//ipfind.co/me?auth=<your_api_key>', function(data) {
  console.log(JSON.stringify(data, null, 2));
});
{
  "ip_address": "116.12.250.1",
  "country": "Singapore",
  "country_code": "SG",
  "continent": "Asia",
  "continent_code": "AS",
  "city": "Singapore",
  "county": null,
  "region": "Central Singapore",
  "region_code": "01",
  "timezone": "Asia/Singapore",
  "owner": null,
  "longitude": 103.8565,
  "latitude": 1.2855,
  "currency": "SGD",
  "languages": [
    "cmn",
    "en-SG",
    "ms-SG",
    "ta-SG",
    "zh-SG"
  ]
}
$.getJSON('//api.ipify.org?format=jsonp&callback=?', function(data) {
  console.log(JSON.stringify(data, null, 2));
});
$.getJSON('//api.ipinfodb.com/v3/ip-city/?key=<your_api_key>&format=json&callback=?', function(data) {
  console.log(JSON.stringify(data, null, 2));
});
{
  "statusCode": "OK",
  "statusMessage": "",
  "ipAddress": "116.12.250.1",
  "countryCode": "SG",
  "countryName": "Singapore",
  "regionName": "Singapore",
  "cityName": "Singapore",
  "zipCode": "048941",
  "latitude": "1.28967",
  "longitude": "103.85",
  "timeZone": "+08:00"
}
$.getJSON('//ipinfo.io/json', function(data) {
  console.log(JSON.stringify(data, null, 2));
});
{
  "ip": "116.12.250.1",
  "hostname": "No Hostname",
  "city": "Singapore",
  "region": "Central Singapore Community Development Council",
  "country": "SG",
  "loc": "1.2931,103.8558",
  "org": "AS3758 SingNet"
}
$.getJSON('//jsonip.com/?callback=?', function(data) {
  console.log(JSON.stringify(data, null, 2));
});
{
  "ip": "116.12.250.1",
  "about": "/about",
  "Pro!": "http://getjsonip.com"
}
$.getJSON('http://ip.jsontest.com/?callback=?', function(data) {
  console.log(JSON.stringify(data, null, 2));
});
{
  "ip": "116.12.250.1"
}
  • Returns IPv6 address if you have one, which may not be what you want
$.getJSON('//geoip.nekudo.com/api/<ip_address>', function(data) {
  console.log(JSON.stringify(data, null, 2));
});
{
  "city": "Singapore",
  "country": {
    "name": "Singapore",
    "code": "SG"
  },
  "location": {
    "accuracy_radius": 50,
    "latitude": 1.2855,
    "longitude": 103.8565,
    "time_zone": "Asia/Singapore"
  },
  "ip": "116.12.250.1"
}
$.getJSON('//www.stupidwebtools.com/api/my_ip.json', function(data) {
  console.log(JSON.stringify(data, null, 2));
});
{
  "my_ip": {
    "ip": "116.12.250.1",
    "others": []
  }
}

Keep in mind that since these are all free services, your mileage may vary in terms of exceeding quota and uptime, and who knows when/if they will be taken offline down the road (exhibit A: Telize). Most of these services also offer a paid tier in case you want something more robust.

Also, as skobaljic noted in the comments below, the request quotas are mostly academic since this is happening client-side and most end users will never exceed the quota.

  • 4/18/2016: Removed freegeoip.net (out of service)
  • 12/21/2016: Removed Hacker Target (out of service)
  • 4/24/2017: Removed Snoopi.io (out of service)
  • 7/16/2017: Updated limitation for free plans that don't support SSL

I would note that for jsonip.com, it will return only your IPv6 address if you have one, which could be undesirable depending on how you're using the information. But +1 for the excellent examples.

$.getJSON('//freegeoip.net/json/?callback=?', function(data) {   if (!data || !data.ip) alert('IP not found'); }).fail(function() {   alert('$.getJSON() request failed'); });

How to get client's IP address using JavaScript only? - Stack Overflow

javascript ip-address clientip
Rectangle 27 11

Well, I am digressing from the question, but I had a similar need today and though I couldn't find the ID from the client using Javascript, I did the following.

On the server side: -

<div style="display:none;visibility:hidden" id="uip"><%= Request.UserHostAddress %></div>
var ip = $get("uip").innerHTML;

I am using ASP.Net Ajax, but you can use getElementById instead of $get().

What's happening is, I've got a hidden div element on the page with the user's IP rendered from the server. Than in Javascript I just load that value.

This might be helpful to some people with a similar requirement like yours (like me while I hadn't figure this out).

-1: The OP specifically mentions "no server side code", yet you use some C#.

<script>var uip='<%= Request.UserHostAddress %>';</script>

aside from using server side code, one should never use the DOM to store data. This is just bad all over. Hainesy has a better idea to just assign to JS var.

How to get client's IP address using JavaScript only? - Stack Overflow

javascript ip-address clientip
Rectangle 27 45

http://ipecho.net/plain appears to be a workable alternative, as whatismyip.com now requires membership for their automated link. They very kindly appear to be offering this service for free, so please don't abuse it.

For more info about why this is the preferred way: whatismyip.com/automation

ipveg.com does not require any authentication or any limitations

windows - How do I find out what my external IP address is? - Stack Ov...

windows networking
Rectangle 27 12

I would use a site like www.whatsmyip.org and parse the output.

checkip.dyndns.com returns a very simple HTML file which looks like this:

<html>
  <head>
    <title>Current IP Check</title>
  </head>
  <body>
    Current IP Address: 84.151.156.163
  </body>
</html>

This should be very easy to parse. Moreover the site is exists for about ten years. There is hope that it will be around for a while.

Unfortunately, the DynDns service is to be used only when you are using their services (dyn.com/support/developers/checkip-tool).

I do use this. It's very easy to parse in most languages- in Python it is a single line of code to remove all the extra lines of code (filebuffer[before:-after] where before and after are the number of characters before and after, and are constants.) @IvanMesic, you don't have to use any of their services to use this site.

windows - How do I find out what my external IP address is? - Stack Ov...

windows networking
Rectangle 27 11

If you have access to a webserver with modphp, you can roll your own:

<?php print $_SERVER['REMOTE_ADDR']; ?>

If you don't want that to get abused, you'll have to keep it secret or add request limits.

Create a file called whatismyip.php in your public_html folder in your website. It can be called anything and be anywhere in your webroot.

Add the line above, and then query your server:

curl http://example.com/whatismyip.php

I added a script like this to my server years ago and it is very useful. Everything else is bizarre overkill.

but we're lazy, that's why we're looking for something quick on SO!

windows - How do I find out what my external IP address is? - Stack Ov...

windows networking
Rectangle 27 6

Unfortunately as of 2013, whatismyip.com charge for the service.

http://www.icanhazip.com is still going strong, 3 years later. Just outputs the IP as text, absolutely nothing else.

You can also use Google if you want to be sure it won't go down, but it can still block you for TOS violations.

But even when they block me, they still tell me my client IP address in the error message.

windows - How do I find out what my external IP address is? - Stack Ov...

windows networking
Rectangle 27 11

As you have found out there is no such thing as a single "local IP address". Here's how to find out the local address that can be sent out to a specific host.

  • Create a UDP socket
  • Connect the socket to an outside address (the host that will eventually receive the local address)

I've never done it this way but I like it. It uses the OS routing table automatically and is much easier than scanning the interface list.

This assumes that you know what an outside address will be. This is often not the case in data centers.

You could always try three that are assigned to different continents (IANA makes this easy) and accept best two out of three.

c++ - Get the IP address of the machine - Stack Overflow

c++ linux networking ip-address
Rectangle 27 176

Connect to the Guest and find out the ip address:

ifconfig

example of result (ip address is 10.0.2.15):

eth0      Link encap:Ethernet  HWaddr 08:00:27:AE:36:99
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
  • for host ip enter 127.0.0.1, and for guest ip address you got from prev. step (in my case it is 10.0.2.15)
  • in your case port is 8000 - put it on both, but you can change host port if you prefer

Go to host system and try it in browser:

http://127.0.0.1:8000

or your network ip address (find out on the host machine by running: ipconfig).

In this case port forwarding is not needed, the communication goes over the LAN back to the host.

On the host machine - find out your netw ip address:

ipconfig
IP Address. . . . . . . . . . . . : 192.168.5.1

On the guest machine you can communicate directly with the host, e.g. check it with ping:

# ping 192.168.5.1
PING 192.168.5.1 (192.168.5.1) 56(84) bytes of data.
64 bytes from 192.168.5.1: icmp_seq=1 ttl=128 time=2.30 ms
...

both port will not be 8000. The host port will be 8000 or whaterver u want, but the guest port should be 80

It took some time, but it worked like charm! :) Thanks buddy! :)

Getting from the VM to the host in this case should be possible by going to the VM and getting ITS IP address (10.0.2.15 as below). To get to the host machine from the VM, the IP is 10.0.2.2 (by convention).

If using NAT for the guest... If the service that is running on the host is bound to 127.0.0.1 only, then the guest cannot use the public ip of the host to connect to that service (example service: privoxy). Instead you need to use 10.0.2.2 as mentioned by Mark, or whatever 'route -n' (run on the guest) shows as the default gateway.

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

portforwarding - Virtualbox "port forward" from Guest to Host - Stack ...

virtualbox portforwarding
Rectangle 27 2

As far as I know, all the connections from a LAN network towards and external server have the WAN Ip of the network (normally the router's). :(

yes, if NAT is in place (which it probably should be)

None that I can think of, as paul points out the router is the one handling this conversion at TCP/IP layer, so I see little margin there. However, as this question has been marked as duplicate, I would suggest searching for similar questions at StackOverflow to see if other users came out with a solution, but I don't see a way to bypass the router translation in here :(

c# - How to find the IP address of system throughout the network - Sta...

c#
Rectangle 27 70

I know this may be kicking a dead horse, but maybe this can help someone. I have looked all over the place for a way to find my local IP address, but everywhere I find it says to use:

Dns.GetHostEntry(Dns.GetHostName());

I don't like this at all because it just gets all the addresses assigned to your computer. If you have multiple network interfaces (which pretty much all computers do now-a-days) you have no idea which address goes with which network interface. After doing a bunch of research I created a function to use the NetworkInterface class and yank the information out of it. This way I can tell what type of interface it is (Ethernet, wireless, loopback, tunnel, etc.), whether it is active or not, and SOOO much more.

public string GetLocalIPv4(NetworkInterfaceType _type)
{
    string output = "";
    foreach (NetworkInterface item in NetworkInterface.GetAllNetworkInterfaces())
    {
        if (item.NetworkInterfaceType == _type && item.OperationalStatus == OperationalStatus.Up)
        {
            foreach (UnicastIPAddressInformation ip in item.GetIPProperties().UnicastAddresses)
            {
                if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
                {
                    output = ip.Address.ToString();
                }
            }
        }
    }
    return output;
}

Now to get the IPv4 address of your Ethernet network interface call:

If you try to get an IPv4 address for a wireless interface, but your computer doesn't have a wireless card installed it will just return an empty string. Same thing with the Ethernet interface.

It was pointed out (thanks @NasBanov) that even though this function goes about extracting the IP address in a much better way than using Dns.GetHostEntry(Dns.GetHostName()) it doesn't do very well at supporting multiple interfaces of the same type or multiple IP addresses on a single interface. It will only return a single IP address when there may be multiple addresses assigned. To return ALL of these assigned addresses you could simply manipulate the original function to always return an array instead of a single string. For example:

public static string[] GetAllLocalIPv4(NetworkInterfaceType _type)
{
    List<string> ipAddrList = new List<string>();
    foreach (NetworkInterface item in NetworkInterface.GetAllNetworkInterfaces())
    {
        if (item.NetworkInterfaceType == _type && item.OperationalStatus == OperationalStatus.Up)
        {
            foreach (UnicastIPAddressInformation ip in item.GetIPProperties().UnicastAddresses)
            {
                if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
                {
                    ipAddrList.Add(ip.Address.ToString());
                }
            }
        }
    }
    return ipAddrList.ToArray();
}

Now this function will return ALL assigned addresses for a specific interface type. Now to get just a single string, you could use the .FirstOrDefault() extension to return the first item in the array or, if it's empty, return an empty string.

GetLocalIPv4(NetworkInterfaceType.Ethernet).FirstOrDefault();

This is a better solution because there is no DNS usability in lots of places and interfaces can have multiple ip addresses. I also utilise a similar method.

The issue with this is that you only return 1 IP address per interface... the last IP, foreach.

@compman2408 - not true, a single interface can have multiple IPs, see en.wikipedia.org/wiki/Multihoming#Variants for all the combos. Obvious example is when running both IPv4 and IPv6, but in the past i have had single ethernet adapter participate in multiple IPv4 networks. Unusual maybe - yet perfectly legal. E.g. for Windows see windowsnetworking.com/articles-tutorials/windows-2003/

@NasBanov This function is only set up to get IPv4 addresses so I'm not even going to talk about IPv6 and its current uselessness. I'm aware of multihoming as connecting to multiple networks on multiple interfaces however have never heard of connecting to multiple networks on the same interface. Even though it seems you're correct that it is actually possible, the <1% of people using their NIC that way would just have to change the function to return an array instead.

@compman2408 so we agree there is an issue :). Not to forget the case when there is >1 interfaces of the same kind, like 2+ physical Ethernet cards or what often is the case, virtual interfaces from VMs and VPNs? You should rename it to GetRandomLocalIPv4() or always return array and leave it at caller's peril to use .first() and ignore the rest

c# - Get local IP address - Stack Overflow

c# networking
Rectangle 27 5

Timezones follow sometimes quirky rules. IP geolocation is anything but precise (notwithstanding the claims of some vendors).

Having said that, you can certainly find the city and country using a Geo IP product such as MaxMind's:

which includes a PHP module

You can then use the MaxMind APIs to try and estimate the user's timezone

If you want to rely on your user's clock rather than the IP address, jsTimezoneDetect works quite well (though it is not perfect).

Neither technique works perfectly in all cases. Be sure you allow your user to correct any auto-generated timezone suggestion.

Maxmind link takes you to a generic FAQ page about all of their products - the timezone FAQ entry seems to have been taken down.

How to find timezone ID from IP address/country name in PHP? - Stack O...

php timezone
Rectangle 27 2

http://myexternalip.com provides this kind of information. To retrieve your IP you have plenty of options:

  • http://myexternalip.com/ - browser + lot's of examples of how to use it
  • http://myexternalip.com/raw - a pure text answer, only your ip, no other crap
  • http://myexternalip.com/json - a resposnse ready for json-parsers, also supports jsonp
  • HEAD http://myexternalip.com - send only a HEAD-request and get the answer

windows - How do I find out what my external IP address is? - Stack Ov...

windows networking
Rectangle 27 2

curl ifconfig.me
curl ifconfig.me/ip

Incase you don't have curl installed,

wget ifconfig.me/ip 2>/dev/null && cat ip

windows - How do I find out what my external IP address is? - Stack Ov...

windows networking
Rectangle 27 2

Since this question was asked a while back, there's now a freely available web service designed specifically to allow you to determine your IP address programmatically, called ipify.

$ curl 'https://api.ipify.org?format=json'

Results in

{"ip": "1.2.3.4" /* your public IP */}

windows - How do I find out what my external IP address is? - Stack Ov...

windows networking
Rectangle 27 2

If the router you are behind speak UPnP you could always use a UPnP library for whatever language you are developing in to query the router for its external ip.

windows - How do I find out what my external IP address is? - Stack Ov...

windows networking
Rectangle 27 21

I like jjvainio's answer. As Zan Lnyx says, it uses the local routing table to find the IP address of the ethernet interface that would be used for a connection to a specific external host. By using a connected UDP socket, you can get the information without actually sending any packets. The approach requires that you choose a specific external host. Most of the time, any well-known public IP should do the trick. I like Google's public DNS server address 8.8.8.8 for this purpose, but there may be times you'd want to choose a different external host IP. Here is some code that illustrates the full approach.

void GetPrimaryIp(char* buffer, size_t buflen) 
{
    assert(buflen >= 16);

    int sock = socket(AF_INET, SOCK_DGRAM, 0);
    assert(sock != -1);

    const char* kGoogleDnsIp = "8.8.8.8";
    uint16_t kDnsPort = 53;
    struct sockaddr_in serv;
    memset(&serv, 0, sizeof(serv));
    serv.sin_family = AF_INET;
    serv.sin_addr.s_addr = inet_addr(kGoogleDnsIp);
    serv.sin_port = htons(kDnsPort);

    int err = connect(sock, (const sockaddr*) &serv, sizeof(serv));
    assert(err != -1);

    sockaddr_in name;
    socklen_t namelen = sizeof(name);
    err = getsockname(sock, (sockaddr*) &name, &namelen);
    assert(err != -1);

    const char* p = inet_ntop(AF_INET, &name.sin_addr, buffer, buflen);
    assert(p);

    close(sock);
}

this gives me priviate ip 127.*.*.* . maybe because i'm behind NAT?

c++ - Get the IP address of the machine - Stack Overflow

c++ linux networking ip-address
Rectangle 27 1

Another way is if you have access to a cloud email (yahoo, google, hotmail), send yourself an email. Then view the headers and you should see your IP address in there.

I would look up the exact area but the headers may vary from each implmentation, Look for the received-by and follow that until you get to something that looks like sent-by

EDIT: This answers the how to find IP address, not the via PROGRAMMATIC approach

Maybe inefficient but if you are on a locked down workstation and cannot get to the external device its another method you may use.

windows - How do I find out what my external IP address is? - Stack Ov...

windows networking
Rectangle 27 1

My WRT54G router tells me through its Local Router Access feature (the http(s) administration interface), and I imagine something similar could be done with many other devices. In this case, the entry page gives the octets of the IPv4 address in four lines containing this phrase:

Where i is the octet value and N is the octet number. This bit of doggerel fetches and parses it for me, courtesy of cygwin:

#! /usr/bin/env perl
use strict;
use warnings 'all';

my( $account, $password ) = @ARGV;

open QUERY,
    "curl --sslv3 --user '$account:$password' https://Linksys/ --silent |"
    or die "Failed to connect to router";

my @ipaddr = ('x','x','x','x');

while( <QUERY> ) {
    $ipaddr[$2] = $1 if /value='(\d+)' name='wan_ipaddr_([0-3])/;
}
close QUERY;
print join('.', @ipaddr);

There is no guarantee that this will work with all versions of the router firmware.

If your router is set to use http for this interface, drop the --sslv3 curl option, and you can use dotted-decimal notation to address the router. To use https with the curl options above, I also did this:

Used a browser to fetch the router's self-signed certificate (saved as Linksys.crt).

openssl x509 -in Linksys.crt -text >> /usr/ssl/certs/ca-bundle.crt
  • Added 'Linksys' to my hosts file (C:\Windows\System32\Drivers\etc\HOSTS on my Win8 box), as an alias for the router's address. If the dotted-decimal notation is given to curl instead of this alias, it rejects the connection on account of a certificate subject name mismatch.

Alternatively, you could just use the --insecure option to bypass certificate verification, which probably makes more sense in the circumstances.

windows - How do I find out what my external IP address is? - Stack Ov...

windows networking
Rectangle 27 1

I consider a better idea is to finding out which timezone is set based on the user client setting. Maybe there is the situation that a user is in a timezone, which he doesn't want to be.

One simple possibility is to ask the user, but that's to easy.

With JavaScript you could find out the offset in minutes from UTC. Also you could find out, if the client is in a country with daylight saving time (DST) and if dst is active. This could be done, by comparing the time of two date objects, one with the month January and one with the month July.

var dst1, dst2, expires, hemisphere, now;

now = new Date(); expires = new Date(); dst1 = new Date(); dst2 = new Date();

expires.setTime(now.getTime() + 31536000000);
setCookie('timezone_offset', now.getTimezoneOffset(), expires, '/');

dst1.setDate(1);
dst1.setMonth(1);
dst2.setDate(1);
dst2.setMonth(7);

if (parseInt(dst1.getTimezoneOffset()) === parseInt(dst2.getTimeZoneOffset())) {
  setCookie('timezone_dst', 0, expires, '/');
} else {
  hemisphere = parseInt(d1.getTimezoneOffset()) - parseInt(d2.getTimezoneOffset());
  if ((hemisphere > 0 && parseInt(d1.getTimezoneOffset()) === parseInt(now.getTimezoneOffset())) || (hemisphere < 0 && parseInt(d2.getTimezoneOffset()) === parseInt(now.getTimezoneOffset()))) {
    setCookie('timezone_dst', '0', expires, '/');
  } else {
    setCookie('timezone_dst', '1', expires, '/');
  }
}

Read the cookie with PHP and interpreting the information of them with timezone_name_from_abbr():

$timezone = timezone_name_from_abbr('', $_COOKIE['timezone_offset'] * 60, $_COOKIE['timezone_dst']);

How would you use the 2 cookies though? Presumably your plan is to use DST or not depending on whether it's active, but the dates when DST transitions vary country to country: en.wikipedia.org/wiki/Daylight_saving_time_by_country

How to find timezone ID from IP address/country name in PHP? - Stack O...

php timezone
Rectangle 27 10

I never figured out Haibu or Cluster. But I did find a good solution that addressed my issue. To my surprise, it was actually quite simple. However, I don't know much about servers, so while this works, it may not be optimal.

I installed the following on Node

Then, as a matter of personal style, I placed all my virtual hosts in a common directory (/localhost)

I then switched Apache to listen on a port other than port 80. I just happened to choose port 9000 because I had seen that used somewhere. (In httpd.conf, changed "Listen 80" to "Listen 9000"). I also had to make sure that all my virtual hosts, as defined in extra/httpd-vhosts.conf were set to an IP based nameVirtualHost (127.0.0.1) instead of using a port (*:80).

On the Node side, I created my app/server (aka node virtual host) that listened on port 8000 (somewhat arbitrarily choice of port number) See this link on creating a server with express: http://expressjs.com/guide.html

Using node-http-proxy, in nodeHttpProxy.js I then created a proxy server that listens on port 80. Using express, which wraps connect (http://www.senchalabs.org/connect/) I created my virtual hosts.

// Module dependancies
var httpProxy = require('/usr/local/lib/node_modules/http-proxy/lib/node-http-proxy')
, express = require('/usr/local/lib/node_modules/express/lib/express');

// Http proxy-server
httpProxy.createServer(function (req, res, proxy) {

    // Array of node host names
    var nodeVhosts = [
        'vhost1'
        , 'vhost2'
    ]
    , host = req.header('host')
    , port = nodeVhosts.indexOf(host) > -1
        ? 8000
        : 9000;

    // Now proxy the request
    proxy.proxyRequest(req, res, {
        host: host
        , port: port
    });
})
.listen(80);

// Vhosts server
express.createServer()
.use(express.vhost('vhost1', require('./vhost1/app')))
.use(express.vhost('vhost2', require('./vhost2/app')))
.app.listen(8000);

As you can see, I will have to do two things each time I create a new Node virtual host:

  • define a new express virtual host using the .set method
node nodeHttpProxy.js

You might get some weird "EACCESS" error, in which case, just run as sudo.

It will listen on port 80, and if the host matches one of the names in the nodeVhosts array it will forward the request to that host on port 8000, otherwise it will forward the the request onto that host on port 9000.

apache - How to use vhosts alongside node-http-proxy? - Stack Overflow

apache node.js proxy vhosts express