Thread: Using postfix in C / detecting IP addresses

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912

    Using postfix in C / detecting IP addresses

    So I'm setting up Ubuntu server 8.04 on a dynamic IP - and I'm writing a script that needs to send me an email whenever the IP changes. So I'm frantically researching the cleanest ways to do this in C - but if you can make some recommendations, you'll probably save me a lot of time and I could avoid going down the wrong path.

    1. I'm behind a router - how can I find the routers WAN address? I know I'm 192.168.1.100 and it's 192.168.1.1, but how can I tell what my address is to the outside?

    2. I see postfix is the default MTA in Ubuntu... I can't seem to get it work though. I try executing it from the command line and from my program through system(), and each time the program ends with no message, and I never receive an email from the other end. I'm guessing I have it configured wrong - I have check with my ISP and they do allow mail servers. Any thoughts?

    I'm aware that Google results for both these topics are numerous - but they all seem to be very low quality, and I'm wary of "trying" any more solutions presented because none of them have worked so far.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Code:
    > tracert -h 2 www.google.com
    
    Tracing route to www.l.google.com [74.125.79.103]
    over a maximum of 2 hops:
    
      1    <1 ms    <1 ms    <1 ms  192.168.0.1
      2     6 ms     5 ms     5 ms  myisp.com [12.34.56.78]
    
    Trace complete.
    Or as many hops as it takes to get across your intranet and one step onto the internet.

    Oddly, I get a different answer from the likes of http://www.whatismyip.com/
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    I was hoping I was missing an obvious system call - I guess it's up to system and manual parsing, eh? Any idea why the IP is different?

  4. #4
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    I highly recommend you use some language like perl or any other language that supports regexes, and then parse it from the HTML of www.whatsmyip.com
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Code:
    ifconfig $IFACE | head -2 | tail -1 | awk '{print $2}' | awk -F: '{print $2}'
    Where $IFACE is your interface (e.g "eth0")

    EDIT: Oh. You're behind a router, so you want your gateway's external address. You'll need to use traceroute to find it.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  6. #6
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    404
    I believe there is a posix regex library. I don't quite know how good it is though.

  7. #7
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    You'll need to use traceroute to find it.
    I don't see how that's gonna work... It shows my router with it's LAN address... The first address that isn't under my LAN is my ISP's router.... Am I mistaken?

    sean@BlackBear:~$ traceroute gmail.com
    traceroute to gmail.com (64.233.161.83), 30 hops max, 40 byte packets
    1 192.168.1.1 (192.168.1.1) 2.388 ms 4.710 ms 5.079 ms
    2 69.169.152.1.provo.static.broadweave.net (69.169.152.1) 14.457 ms 14.835 ms 15.173 ms
    3 ge-6-6.car1.SaltLakeCity1.Level3.net (4.53.40.29) 15.544 ms 15.911 ms 16.278 ms

    If I'm not mistaken, 69.169.152.1 is NOT my house. Unless I am indeed mistaken, I guess it's down to using PHP...

  8. #8
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by sean View Post
    I don't see how that's gonna work... It shows my router with it's LAN address... The first address that isn't under my LAN is my ISP's router.... Am I mistaken?
    No, I'm just dumb.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting 32 bit binary IP to decimal IP (vice-versa)
    By Mankthetank19 in forum C Programming
    Replies: 15
    Last Post: 12-28-2009, 07:17 PM
  2. Replies: 1
    Last Post: 09-11-2004, 08:52 AM
  3. resolving names and ip addresses
    By dicky in forum Networking/Device Communication
    Replies: 5
    Last Post: 07-01-2004, 03:32 PM
  4. increment IP addresses - newbie Q.
    By webwesen in forum C Programming
    Replies: 6
    Last Post: 09-09-2003, 08:25 AM