Thread: How to get remote/external IP in C

  1. #1
    Registered User
    Join Date
    Oct 2013
    Posts
    4

    How to get remote/external IP in C

    Hallo people,

    I am starting to learn C, its quite an easy language to learn from the basics, I hope to learn others as time goes, I wonna know how do I get the external / remote IP of a computer? Pls let me know.

  2. #2
    Registered User (^Burt^)'s Avatar
    Join Date
    Sep 2013
    Posts
    26
    I found the easiest way in C# was to setup an external webpage which simply displayed my IP address and then extract the address from the website programmatically at runtime.
    Very simple in C# but from what I have read (just) pretty complex in C.

    May be a start point.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User (^Burt^)'s Avatar
    Join Date
    Sep 2013
    Posts
    26
    That would only give the internal/local IP address though wouldn't it?
    I guess it depends on the network setup but my external/public IP address rests at the router and appears unknown to the local machine. I too am interested in a method to discover the external IP address without parsing it off a website.

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you can try to parse output of tracert command to some external host

    1st line should be your local IP
    2nd line - your local network address of the router
    3rd line - your public network address of the router...

    It is not very reliable - but for the fixed network structure with only Public IP changes - should work

    Or implement the tracert-like behavior yourself... As I understand it is Ping with limited TTL
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  6. #6
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Have found following link
    http://api.externalip.net/ip
    So you send the Http request and get the Ip back - no parsing required...

    For HTTP request/response you can use curl
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  7. #7
    Registered User (^Burt^)'s Avatar
    Join Date
    Sep 2013
    Posts
    26
    Quote Originally Posted by vart View Post
    Have found following link
    http://api.externalip.net/ip
    So you send the Http request and get the Ip back - no parsing required...

    For HTTP request/response you can use curl
    Even better if you setup your own page so that you remain in control of it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Remote Registrys
    By wierdbeard65 in forum Windows Programming
    Replies: 2
    Last Post: 06-25-2008, 07:32 AM
  2. COM ports on remote PCs...
    By BrownB in forum C++ Programming
    Replies: 3
    Last Post: 07-10-2006, 11:28 AM
  3. remote dirinfo
    By AngKar in forum C# Programming
    Replies: 0
    Last Post: 06-19-2006, 12:54 PM
  4. Remote Control
    By nvoigt in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 05-19-2003, 07:31 AM
  5. wow sub 7? remote?
    By Shadow in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 05-11-2002, 07:24 PM