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.
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.
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.
Have you looked at gethostbyname()?
Winsock Programmer’s FAQ: Get the Local IP Address(es)
"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
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.
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
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