Amit Agarwal

Linux and Photography Blog
tools
international

For last couple of days, I was thinking of putting this. I was thinking of some way to get the IP address of the client directly rather than going through some site or parsing the content. So here it is.

Now the trick here is simple. There are two ways to get the IP address of the client in the php script and thus a simple script like the below would capture both of them.

<?php

$ip=@$REMOTE_ADDR;
echo “<html><body><font size=’3′><b>IP Address= $ip</b><br>”;
$ip1=$_SERVER['REMOTE_ADDR'];
echo “<font size=’3′><b>IP Address= $ip1</b>”;
?>
</body></html>

Now this can be used in scripts to get you IP address very quickly if only there were no html tags and no junk and only the IP address. So here is a direct link to your IP alone.

This is a php which does not create any text and thus you can get the IP adress directly without parsing too. There are two lines in the file and both contain the IP address :)

Here is an example to use in bash scripts:

wget http://amit-agarwal.co.in/mystuff/getip_txt.php -O ak 2>/dev/null && ip=`tail -1 ak`

After you have executed the above the IP address used by your client is put in the variable ip. You can check this with http://whatismyip.com for this first time to verify it is working fine. So enjoy scripting.

Enter Your Mail Address

Get you ip address like whatismyip.com
Hot:sun Get you ip address like whatismyip.comsun Get you ip address like whatismyip.comsun Get you ip address like whatismyip.comsun Get you ip address like whatismyip.comsun dark Get you ip address like whatismyip.com

You are welcome to my blog. Please feel free to share your Good or Bad experiences with me through comment or through email.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • blogmarks
  • Blogosphere News
  • co.mments
  • HelloTxt
  • Ping.fm
  • Reddit
  • RSS
  • StumbleUpon
  • Suggest to Techmeme via Twitter
  • Technorati
  • Twitter
  • Yahoo! Bookmarks
  • Add to favorites
  • BlinkList
  • Diigo
  • email
  • Identi.ca
  • LinkedIn
  • Live
  • MyShare
  • MySpace
  • PDF
  • SheToldMe
  • Slashdot
  • Socialogs
  • Tumblr

related post

Technorati Tags: , , ,

Get you ip address like whatismyip.com

Facebook comments:

5 Comments »

  1. interesting i just happened to look at the source code for:
    http://www.whatismyip.com/

    and saw in a comment that this link:
    http://www.whatismyip.com/automation/n09230945.asp

    gives you just the ip address with no html.

    but this is all news to me. i have a script running several times a day to parse another website that gives ip addresses. i check it because i don’t have a static ip address and i want the system to email me when ever it sees that my router’s ip address has changed. i can then update the dns record for my domains. anyway, it will be a simpler script if i don’t have to filter out the ip address. and more reliable too if the site i use ever changes their format.

    thanks

  2. Thanks for the nice comment. BTW, I could never get http://www.whatismyip.com/automation/n09230945.asp to get the IP.

  3. How do I get this to work on my website?

  4. I did not get your question. What to work?

  5. I am honestly thankful to you for providing us with this invaluable data. My spouse and I are in reality grateful, just simply the data we needed.

RSS feed for comments on this post. TrackBack URL

Leave a comment



IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)

What is 15 + 10 ?
Please leave these two fields as-is:
advertise
tour

© 2010 Amit Agarwal | Entries (RSS) and Comments (RSS) | Valid CSS 2.1 Valid XHTML 1.0 Transitional

Powered by Wordpress 3.0, design by Abel, handcrafted by Abel County Laboratories, based on Wsg Standards Wsg Standards

jobs

Switch to our mobile site

Page optimized by WP Minify WordPress Plugin