What Is My IP Address? - IP Address Lookup, Bandwidth Speed Test, IP Info, plus more

Go Back   What Is My IP Forum > All About Code > Coding Problems

Notices


Closed Thread
 
Thread Tools Display Modes
  #1  
Old 12-18-2008, 03:42 PM
maori maori is offline
Junior Member
 
Join Date: Dec 2008
Posts: 1
Default getting external IP

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  
Old 12-24-2008, 12:34 AM
clanmills's Avatar
clanmills clanmills is offline
Super Moderator
 
Join Date: Jul 2008
Location: San Jose, CA
Posts: 190
Send a message via MSN to clanmills Send a message via Skype™ to clanmills
Default

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>
and on Windows:
Code:
c:\>curl "http://whatismyip.com/automation/n09230945NL.asp"
68.166.189.117

c:\>
(curl is a wonderful opensource command-line program for internet things)

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()).
Closed Thread

Bookmarks


Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 12:42 AM.


What Is My IP - IP Command Lines - What is an IP Address - Speed Test - IP Address FAQ

Need IP address location detection service? Get it from IP2Location.com now.

Powered by vBulletin®
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright - WhatIsMyIP.com