Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

External Ip

Posted on 2006-07-18
10
Medium Priority
?
1,429 Views
Last Modified: 2011-10-03
Hi.

How can i get my external ip ??
(A question asked a million times BUT i only get local ip from other PAQ solutions)

I am behind a router !...
Is there a way to get it except visiting a page and grab the ip string?

I found a promising PAQ here :
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21408046.html

Everything works except "FCurrentIpAddress".
I get a memory read/write error when i try to use it.

Thanks in advance.
0
Comment
Question by:CodedK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 11

Accepted Solution

by:
calinutz earned 1000 total points
ID: 17128708
function TForm1.checkRealIP(Sender:TOBject):string;
var
 sx:string;
 i:integer;
begin
  sx:=IdHTTP1.Get('http://www.whatismyip.org/');
  Application.ProcessMessages;
  i:=1;
  while sx[i] in ['0'..'9','.'] do
    inc(i);
  delete(sx,i,length(sx));
  checkRealIP:=sx;
  idHTTP1.Disconnect;
end;



....
Edit1.Text:=CheckRealIP(self);
....
0
 
LVL 11

Expert Comment

by:calinutz
ID: 17128712
No other ways of detecting the real IP otherwise... None that I know of anyways...

Regards
0
 
LVL 16

Author Comment

by:CodedK
ID: 17128721
Hi calinutz.

Thanks but i have that code ... :/
I allready said : "except visiting a page and grab the ip string"

Chack that link i gave... It can get every other info.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Expert Comment

by:2266180
ID: 17128821
codedk, there is absolutly no way of getting the real IP address except getting it from an external source (like a website or dedicated server). there are tons of ways to "turn" a LAN ip into an external one, and most of them use software, and not hardware, so there is no standard. the best and easiest way is to use one of the showmyip pages, just as calinutz suggested.
0
 
LVL 16

Author Comment

by:CodedK
ID: 17128863
:)

Hi ciuly.
Ok, i guess i knew that (or saw that coming) , but one last thing...
Since i've used katka source (link above) to get all the other info (Hardware oriented solution),
can anyone make the FCurrentIpAddress work ? (Just out of curiocity coz every other info worked).
Maybe its my hardware the problem thats why i'm asking.
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17129235
actually, certain routers will let you query them and will tell you your external ip (via telnet etc)
try
telnet (router ip address)
and see if you can find a command to show you the external ip your isp has assigned you.
be careful in there though :-)
some specific ISPs have a webpage also, but you do not want this approach
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17131427

GetAdaptersInfo can NOT be used to resolve your external IP address, but there is a way using iphlpapi and the function GetBestRoute.

It basically amounts to starting with the local address and giving it a dest address; something like "www.google.com". This will fill in a block giving you the next forward address. Then its a matter of calling GetBestRoute again until the address is no longer in the private address range of 192.x.x.x / 10.x.x.x. (then you need to add 1 to the final byte of x.x.x.x).

I can provide an example shortly if you would find it helpful

Russell
0
 
LVL 16

Author Comment

by:CodedK
ID: 17131449
I'd like that Russell.
Thanks :)
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17133203

Never mind...
The problem is not that it doesn't work, its just that the routing table information is for the *outbound* direction. The inbound direction (how others see your IP), and the route path that they would use to get to you is not always the same as the outbound path. For your problem, the most reliable (and generic) solution is going to be connecting to one of the numerous 'whats my ip' sites and parsing the IP address out.

Regards,
Russell
0
 
LVL 16

Author Comment

by:CodedK
ID: 17134523
:) Ok thanks for all the suggestions.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question