Get you ip address like

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.


echo \”<html><body><font size=\’3\’><b>IP Address= $ip</b><br>\”;
echo \”<font size=\’3\’><b>IP Address= $ip1</b>\”;

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 -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 for this first time to verify it is working fine. So enjoy scripting.

6 thoughts on “Get you ip address like”

  1. interesting i just happened to look at the source code for:

    and saw in a comment that this link:

    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.


  2. It’s a shame you don’t have a donate button! I’d certainly donate to this brilliant blog! I guess for now i’ll settle for
    book-marking and adding your RSS feed to my Google account.
    I look forward to fresh updates and will talk
    about this blog with my Facebook group. Talk soon!

This site uses Akismet to reduce spam. Learn how your comment data is processed.