L2.IO

Get Client's IP Address from Javascript...and more


NEWS

2015-07-03: Added an IPv4 only URL.
2015-06-24: Added IPv6 support.
2015-06-23: Serves now 2.500.000
requests per Day.
Tested at 6.000.000 per Hour.
2015-06-22: Corrected minor XSS
vulnerability.
2015-06-18: HTTPS is there !
2015-01-13: 1.200.000 Hits per Day.
Adding 1 more server.
2014-11-06: More than 660.000 Hits
per Day and growing !
2014-11-05: Servers has been tested
at 10.000.000 Hits per Day.
2014-10-20: We have now reach
300.000 Hits per Day !

COMMING SOON

A new Variable for Country Code

UNDER DEVELOPMENT

A new Variable for Country Name

Get IP Address with a simple HTTP(s) request

This basic API permits you to get the public IP address of the system making the call.
The function returns a Text String with the IP address of the caller in either IPv4 or IPv6 format,
depending on your request's protocol.

Syntax : https://l2.io/ip Try it!
Diplay/Get Plain Text User's IP address
IPv4 32-bit (four-byte) format, e.g. 195.80.156.70
IPv6 128-bit format, e.g. 2a00:1b11:115:102:195:80:156:70

If your script only supports IPv4 answers, you may want to use the following call to force IPv4:

Syntax : https://www.l2.io/ip Try it!
Diplay/Get Plain Text User's IP address
IPv4 32-bit (four-byte) format, e.g. 195.80.156.70

The following examples show how you can use this API from various language.
#shell
perl
python
vb.net
#!/bin/sh
#Simple request using curl from a shell script.
#If your OS supports a dual stack IPv4/IPv6 you can add -4 or -6 option
#to force protocol selection, e.g. $(curl -4 -s https://l2.io/ip).

myip=$(curl -s https://l2.io/ip)
echo "My IP is $myip"
#!/usr/bin/perl
#Debian library : apt-get install libwww-perl
use LWP::UserAgent;

my $useragent = new LWP::UserAgent();
my $myip = $useragent->get('https://l2.io/ip')->content;
print 'My IP address is: '. $myip;
#!/usr/bin/env python
#Debian library : apt-get install python-requests
from requests import get

myip = get('https://l2.io/ip').text
print 'My IP address is: ', myip

Dim wc as New System.Net.WebClient
Dim myip as String = wc.DownloadString("https://l2.io/ip")

MessageBox.Show(myip)






Obtaining Visitor's IP Address in Javascript

Syntax : <script type="text/javascript" src="https://l2.io/ip.js?var=myip"></script>
Set javascript variable "myip" to client's IP address
--> myip = "x.x.x.x";
<script type="text/javascript">
  var userip;
</script>
...
<script type="text/javascript" src="https://l2.io/ip.js?var=userip"></script>
...
<script type="text/javascript">
  document.write("Your IP is :", userip);
</script>
Syntax : <script type="text/javascript" src="https://l2.io/ip.js"></script>
Display Client's IP address in your HTML page using javascript
--> document.write('x.x.x.x');