LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-05-2006, 09:04 PM   #1
anakganteng
LQ Newbie
 
Registered: Feb 2006
Location: Jakarta, Indonesia
Distribution: Fedora Core 4
Posts: 6

Rep: Reputation: 0
Question 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
 
Old 07-05-2006, 09:18 PM   #2
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD
Posts: 2,114

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
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).
 
Old 07-05-2006, 09:24 PM   #3
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 59
Quote:
I am currently setting up a server on my home machine...
will this server be used for public services over the internet? ie ftp, http, ssh, etc etc..? if so, then your ip address will be exposed to the internet...everyones IP is.
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.
 
Old 07-05-2006, 11:39 PM   #4
irpstrcr
Member
 
Registered: Mar 2005
Location: LAX
Distribution: Slackware
Posts: 40

Rep: Reputation: 15
Quick and o so dirty....

PHP Code:
#!/bin/bash
lynx -dump checkip.dyndns.org |grep Current |awk '{print "<pre>" $4 "</pre>\n"}' > /tmp/myip.html
date 
>> /tmp/myip.html
mail 
-"My Home IP Addy" email@addy < /tmp/myip.html 
Not positive on the mail part as I use scp to move the html to one of my outside hosts, tho it should be close enough that you could finger it out if it is wrong.
 
Old 07-06-2006, 12:08 AM   #5
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD
Posts: 2,114

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
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])
It is the "furthest down" of the two "Received" lines. You can see this "Received" line in context in the full email source listed below:
Code:
From - Wed Jul  5 21:53:03 2006
X-Account-Key: account2
X-UIDL: 1fYkUU4Vn3Nl34c4
X-Mozilla-Status: 0001
X-Mozilla-Status2: 00000000
Status:  U
Return-Path: <my_email@earthlink.net>
Received: from pop-tawny.atl.sa.earthlink.net ([207.69.195.67])
by mx-stork.atl.sa.earthlink.net (EarthLink SMTP Server) with ESMTP id 1fYkUU4Vn3Nl34c2
for <my_email@earthlink.net>; Wed, 5 Jul 2006 23:52:40 -0400 (EDT)
Received: from cpe-AAA-BBB-CCC-DDD.co.sprintbbd.net ([AAA.BBB.CCC.DDD] helo=[192.168.0.52])
by pop-tawny.atl.sa.earthlink.net with esmtp (Exim 3.36 #10)
id 1FyKuu-0001v4-00
for my_email@earthlink.net; Wed, 05 Jul 2006 23:52:40 -0400
Message-ID: <44AC891B.1060600@earthlink.net>
Date: Wed, 05 Jul 2006 21:52:59 -0600
From: ME <my_email@earthlink.net>
User-Agent: Debian Thunderbird 1.0.7 (X11/20051017)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: ME <my_email@earthlink.net>
Subject: test email
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-ELNK-Info: spv=0;
X-ELNK-AV: 0
X-ELNK-Info: sbv=0; sbrc=.0; sbf=00; sbw=010;
No need to do anything fancy to determine your IP address. It's there by default in any/every email you send. It can be spoofed, but since you're the one sending the email I doubt you'll go out of your way to spoof yourself!
 
Old 07-06-2006, 12:32 AM   #6
binary_y2k2
Member
 
Registered: Jul 2005
Location: England, UK
Distribution: Ubuntu 8.04 Server, Kubuntu 12.04
Posts: 698
Blog Entries: 1

Rep: Reputation: 31
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
in to rc.local and make a cron script with
Code:
sendmail you@yahoo.com < /tmp/myip
 
Old 07-06-2006, 12:50 AM   #7
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD
Posts: 2,114

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
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
 
Old 07-06-2006, 01:03 AM   #8
binary_y2k2
Member
 
Registered: Jul 2005
Location: England, UK
Distribution: Ubuntu 8.04 Server, Kubuntu 12.04
Posts: 698
Blog Entries: 1

Rep: Reputation: 31
Yeah, that would work too, maybe better.
I just expanded on the example by irpstrcr
 
Old 07-06-2006, 01:22 PM   #9
anakganteng
LQ Newbie
 
Registered: Feb 2006
Location: Jakarta, Indonesia
Distribution: Fedora Core 4
Posts: 6

Original Poster
Rep: Reputation: 0
Thumbs up

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

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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
automatically send an email to new users....? oru Slackware 2 09-14-2007 03:56 AM
Need a way for slack server automatically send various notifications cav Slackware 3 04-20-2006 06:48 PM
email 'send' NO - email 'receive' YES..? captain skywave Linux - Wireless Networking 4 04-23-2005 04:35 AM
email 'send' YES - email 'receive' NO..? captain skywave Linux - Wireless Networking 1 04-22-2005 06:23 AM
Allowing an IP to send email using my email server... culprit Linux - Networking 7 09-09-2003 01:24 PM


All times are GMT -5. The time now is 10:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration