Help with getting a servers IP address
Hi All,
I'm in need of a little assistance as to how I should go about my current problem.
I have a home network that has the ability to allow me to VPN into it from anywhere with an internet connection, this is great but! I do not have a static IP address, so I had the following idea to ensure I can always get my flats IP address no matter where I am.
I have an On-line hosted website that is not hosted by myself therefore the IP will NOT change, so what I want to do is get the WEB Server in my flat to gets it own WAN IP and then update the database on my External Web server every few minutes.
This way if I am ever out of the flat and decide I need to VPN and I don't realize my flat mate has reset the modem (New IP) all I need to do is go to http://www.mydomain.com/flats-ip.php and I can see my up-to-date IP address.
Now my first thought was something like this
<?php
$ip = $_SERVER['PHP_SELF'];
//Then upload IP to web server.
?>
Would this be sufficient? I am by no means a PHP guru so bare with me and any pointers would be appreciated
I then need to work out how to execute a script every few minutes, is this possible with PHP? without me having to run the PHP in my browser?
If it is possible I am sure a quick Google search should do the trick.
Or Would there be a better language to code this in?
So I hope you know what I am trying to achieve, any help would be great. If you need any more information please ask.
Thank you and KNOWLEDGE IS POWER!
Relentless.
teammatt3 posted this at 01:46 — 10th September 2008.
He has: 2,102 posts
Joined: Sep 2003
You're on a Windows machine right? I think the easier solution would be signing up for No-IPs free DNS service, and using their Dynamic Update Client. It is usually used for web servers, but it doesn't really matter. All that matters is that when you login to your no-ip account, you'll see your up to date IP. It's not as cool as writing a program to do it, but it gets the job done.
teammatt3 posted this at 01:50 — 10th September 2008.
He has: 2,102 posts
Joined: Sep 2003
Actually, I think you could even just use your no-ip subdomain when you connect to your VPN service (you wouldn't even have to check your account). Relentless.no-ip.org (for example) would always point you at the right place for your VPN.
pr0gr4mm3r posted this at 01:54 — 10th September 2008.
He has: 1,502 posts
Joined: Sep 2006
Solution #1:
To answer your specific question, you would need a script on your server that would log the IP address of the client accessing it. For example, something like this on your server:
<?php
file_put_contents('ip.txt', $_SERVER['REMOTE_ADDR']);
?>
Then, whenever you want to know your IP address of your home network, just call up example.com/ip.txt (assuming that the PHP script is stored at example.com).
Now a computer from your home network will have to periodically load that PHP script from your server so it would update. The easiest way I can think of would be to write a small Windows program that sends a hit to that URL every few minutes. You could also add a meta refresh tag to that php script above that would tall a browser to refresh the page after a set amount of time, but then you would have to leave a browser open on a computer.
Solution #2:
There is a free Dynamic DNS service by No-IP and a couple other companies that will do all of this for you.
I vote for #2.
Edit: darn it, Matt beat me to it
S33ker posted this at 02:22 — 10th September 2008.
They have: 38 posts
Joined: Jun 2008
Thank you both for your help i would love to solve this through creating a program, but some times you shouldn't re-invent the wheel going to take a look at this no-ip thing
Thanks again!
Relentless!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.