- Home
- Contact
-
Articles / Code
- HTML/CSS (2)
-
Scripts (17)
- Twitter & bash
- Generate sitemaps
- random floating point in bash
- Gmail script
- Python http POST requests
- Bashrc enhancements
- commandline <> nautilus
- Word Definitions
- Synonyms
- mysqld monitor
- remote server
- links and emailaddresses
- Apache Analyser
- remote ipaddress
- OOP Python
- mysql tuning
- diskspace notification
- Server Configuration (6)
- ICT-security (2)
retrieve your remote IPaddress from the commandline
» Articles / Code » Scripts » retrieve your remote IPaddress from the commandline
There are many websites that offer a service to view you remote ip-address, like for example my.ip or myip.org
But what if you don't want to use your browser? Wouldn't it be nice if you could just ask for your remote ip-address from the commandline? What you would need is a remote server that sends you your ip.
This can easily be done in php:
<?php
#shows remote ip adres.
# use HTTP_X_FORWARDED_FOR in case of of rev.proxy
#$a = $_SERVER['HTTP_X_FORWARDED_FOR'];
$a = $_SERVER['REMOTE_ADDR'];
echo $a;
?>
You can simply point your browser to this script on your server and it will show your ip. My script is located at www.lxer.nl/ip.php
But you don't want to use a browser, you want to use the commandline. Using Python is probably the easiest way to script this:
#!/usr/bin/python
import urllib
# Get a file-like object
f = urllib.urlopen("http://www.lxer.nl/ip.php")
# Read from the object, storing the page's contents in 's'.
s = f.read()
print s
f.close()
Damn simple... :)
Now name this script for example 'ipremote' and put it in /usr/bin. Make sure it is executable (chmod 775), and you can simply use:
$~> lx@zxz:~$ ipremote
194.109.238.xx
Post your comment
Comments
No one has commented on this page yet.
RSS feed for comments on this page | RSS feed for all comments