Tags: IP Address Lookup, Information, and Location, Test Your Internet Connection Speed
|
#1
|
|||
|
|||
|
hi guys i'am trying to recive my external IP in a c++ application (learning) so from what i have read because i'am behind a router easiest way would be to use a 3dr party ie webpage and grap the info from there ? so i made this simple php code uploaded to my server and it does display my IP <?php $ip = $_SERVER['REMOTE_ADDR']; print $ip; ?> can anyone tell me how to pass this in a simple c++ app witch just has a edit box in it ie as soon as you start the app it display the IP i'am at a loss here i tried a few ways i found though google but they didnt work TIA |
|
#2
|
||||
|
||||
|
You probably won't believe how difficult it is to do this in C++. It'll take about 30 lines of code! (I told you that you wouldn't believe it!). You have to create a socket, connect to a server, send the HTTP request, wait for the reply and then parse off the headers from the response. Oh, and you have to remember to initialize the socket library and link your code.
And that's before we arrive at the GUI, which is never cross-platform in C++. However, let's make it easier by simply printing the result to stdout (in Windows cmd console, or a Unix terminal). Like this (on the Mac): Code:
515 /Users/rmills> curl "http://whatismyip.com/automation/n09230945NL.asp" 68.166.189.117 516 /Users/rmills> Code:
c:\>curl "http://whatismyip.com/automation/n09230945NL.asp" 68.166.189.117 c:\> Now you'll understand why folk prefer the P scripting languages (like PHP, Perl and Python, or even the equally awesome Java, JavaScript and Ruby). And of courses the Scripting languages are cross-platform. Anyway, we could turn this into a little game to see who can write the shortest (portable) C++ to do the same as the curl command above (using sockets, not system()). |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|