How to log your own IP

Call me paranoid but ever since the antics of ACS:Law in the noughties I've been logging my IP address, it is not because I'm am an illegal downloader, my intrigue came about from the thought of how you would prove that you didn't if I was wrongly accused.

Stay with me here, but think of the things that can go wrong in the chain of collecting torrentors IPs, requesting the info from the ISP and collating and issuing all the thousands of law suits - there are any number of times a transposition of an IP address or a time and date could happen. Hell, even the music industry didn't like the way some people were doing it!

So my solution was to log my IP address, I've been doing it for five years now and even though my RaspberryPi is also logging my IP in a couple of different ways: through Syslog-ng by logging all of my router activity and through running a cron job to dynamically update its IP address to the DNS server.

It is trickier than you think to get your external ip address, ipconfig will only tell you your internal ip:

This is because of NAT Loopback so we'll need to find another way. Google will tell you your IP address if you google it, but it will be much simpler to get it from another source that returns just the IP address in plain text so we don't have to clean up the html. For this we are going to use, I'm not abusing their service here as I already use them as my DNS.


These instructions are for windows users only, this is on the basis that if you are a linux user you'll either a) already know how to do this or b) know how to modify this for your own requirements.

Set up your folder

Create a new directory somewhere safe on your computer, I called mine logmyip, if you are using Windows 7 you may come into a few security issues when trying to change the contents of some of the files after you've created so you may as well go ahead and get it all working in another directory within your documents for example.


Wget is a software package for retrieving files using HTTP, HTTPS and FTP, it is run in the command line and comes as standard with any Linux distro. For windows its a little harder to get hold of because you are expected to compile it yourself from the source code but you can download the windows binary from gnuwin32 at sourceforge, direct link (currently 1.11.4). Extract wget.exe from the zip to your newly created folder.


Next all we need is to set up the logging script, we'll be using a batch command. Open Notepad (or similar) then paste the following text in then save as logmyip.bat. Make sure you do not save it as a text document as it won't work, choose 'All files' in the save dialogue.

echo off
CHOICE /T 10 /C ync /CS /D y
wget -q -O %temp%\\ip.txt
set /p var1=<%temp%\\ip.txt
echo %date% %time% %var1%>>iplog.txt
del %temp%\\ip.txt


This next step is not compulsory but I prefer it as it will run the script 'silently', i.e. won't flash up any annoying boxes when it runs - we'll be using a bit of vbs for this. Same as above, fire up Notepad and get the code saved down:

dim fso
dim curDir
dim WinScriptHost
set fso = CreateObject("Scripting.FileSystemObject")
curDir = fso.GetAbsolutePathName(".")
set fso = nothing
Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run chr(34) & curDir & "\\logmyip.bat" & chr(34), 0
set WinScriptHost = nothing


There are a couple of choices here, depends how often you want to log you IP address. My Sky router is pretty stable and doesn't reset itself very often resulting in a change of IP - I only run it once a day. I've scheduled this but just getting it to run at startup. This is easy to setup - right-click the vbs file you created above and copy, then right-click somewhere in your folder and paste a shortcut. Then all you do is drag this shortcut over to the start menu, then keeping the left click on navigate through 'All programs' then into the startup folder. Job done  - it will then run every time you boot up.

If you need to log more often than this you can schedule it in Task Scheduler.

Running a my ip script on your own server

If you want to host your own IP revealer, just use this php code below:

    if ($td=="y") {
        echo date("d/m/Y H:i:s", time())." - ".$_SERVER['REMOTE_ADDR'];
    else {
        echo $_SERVER['REMOTE_ADDR'];

It is also coded that if you run the query string ?td=y then it will also spit out the server time and date, you can check it out here.


Share page

Subscribe to newsletter

Search Posts

Back to top