Looking for a way to automatically send current real IP to email
I am currently setting up a server on my home machine running on dynamic IP, behind a router. I could use no-ip.com to keep track of the current IP, however that will expose my IP to the internet.
What I intend to do is to make a script that will automatically send me an email to my web-based email (yahoo.com) on daily basis with its current IP. The problem is, since the machine is behind a router, I am only able to retrieve the NAT translated IP using ifconfig , where what I need is the real IP that the internet sees. After looking around, I found that I can get the real IP by ssh to somewhere, and do 'echo $SSH_CLIENT'. However to do so automatically, I would probably need to set up a passwordless ssh connection, which I dont think is the proper way to do so. So to sum up, I need a way for my machine that is behind NAT to automatically send me email containing its current 'real' IP. Please point me to any program that can do this, or a command that can allow me to retrieve the network 'real' IP Many thanks for those kind enough to read this lengthy post :p |
Just send a totally blank email. Your current WAN IP (your "real IP address") will automatically be added to the email header. You don't have to do a thing to determine it, nor add it to the email manually.
When you receive the email, choose your email client's "View Message Source" (or equivalent) function. Check out the "Received: " headers. The IP address you want will be in the FURTHEST DOWN "Received" header, since as the email transverses various servers, new "Received" lines are prepended to the top of the email. How many total "Received" headers you have will depend on the specific path the email took when being relayed from server to server. The only one you care about is the first header (the furthest down one). |
Quote:
i also have a dynamic ip address and used to host services, and many times did not know the ip address.. i used dyndns.org to get a freehostname which was linked with my ip address, so all i needed to remember was the hostname. it was automatically updated (through my router) whenever i was reconnected and recieved a new ip address. your router has a public ip address.. your computer that uses this router does not, it has a private lan ip address. do you want the script to get the ip address of your computer? ie the private one? if so, then i dont see how this would be useful... only the router ip address would be. your router should have a built in firewall.. so just because your routers IP address is known to the internet doesnt make your network insecure. besides the routers firewall, your server will (or should) have a firewall as well, meaning even more security. hope this helps.. or let me know if im misunderstanding. |
Quick and o so dirty....
PHP Code:
|
Below is a test email I just sent to myself. I entered a Subject line of "test email" and nothing else. My real IP address is there by default - I didn't have to manually determine and enter it.
You can see my real IP address in the "Received" line about 1/3 of the way down in the email source listing below. I manually overwrote the IP address with "AAA.BBB.CCC.DDD", but in the actual message my true IP address was listed. You can also see on that same "Received" line my internal IP address is listed as well (not that this is of any use to anyone): 192.168.0.52 The specific "Received" line I'm talking about is this one: Code:
Received: from cpe-AAA-BBB-CCC-DDD.co.sprintbbd.net ([AAA.BBB.CCC.DDD] helo=[192.168.0.52]) Code:
From - Wed Jul 5 21:53:03 2006 |
If you don't want to look at the message source, or even have to open the massage, just put
Code:
echo "Subject: Your IP is $(lynx -dump checkip.dyndns.org |grep Current |awk '{print $4"}')" > /tmp/myip Code:
sendmail you@yahoo.com < /tmp/myip |
Oh! Now I see what you guys are suggesting with that lynx thing!
Another similar alternative (if you like HTML email): Code:
wget -q -O - checkip.dyndns.org | mail -s "Your Current IP Address" -a "Content-Type: text/html" your_email@your_isp.com |
Yeah, that would work too, maybe better.
I just expanded on the example by irpstrcr |
SUPERB!!! thanks a lot guys! that really answers my question and more!! learned something today :)
->When you receive the email, choose your email client's "View Message Source" (or equivalent) function. Check out the "Received: " headers. <- ARGH why didnt I think of this before, such a simple solution... Now I gotta check out whats the lynx all about :D BTW, yea this server is only for my own use, not for public, and I am looking for my router IP. Sorry I didnt make it clearer... Again I appreciate your time and for sharing your knowledge. |
All times are GMT -5. The time now is 02:39 AM. |