?
Solved

Real IP

Posted on 2011-05-04
6
Medium Priority
?
790 Views
Last Modified: 2012-05-11
I want get my real address ip on internet
I have found in another post this code
by i have an error like in picture
procedure TForm1.Button5Click(Sender: TObject);
var s:string; i:integer;
begin
  s:=IdHTTP1.Get('http://www.whatismyip.com/');
  delete(s,1,pos('Your IP Is',s)+10);
  i:=1;
  while s[i] in ['0'..'9','.'] do
    inc(i);
  delete(s,i,length(s));
  showmessage(s);
end;

Open in new window

2.jpg
0
Comment
Question by:wackyteseo
  • 4
6 Comments
 
LVL 8

Expert Comment

by:TheMak
ID: 35688751
Directly open http://www.whatismyip.com/ website and you will see on the top your Real IP address.

Regards,
0
 
LVL 9

Expert Comment

by:Mahdi78
ID: 35688854
You're getting forbidden access to the website http://www.whatismyip.com/ , maybe your country or idhttp agent are denied.
Do you get this error when you browse the site with internet explorer or Firefox?
0
 
LVL 4

Accepted Solution

by:
fromer earned 1000 total points
ID: 35688916
Here is what I found from Google...

Here is The Source Site..
http://delphi.about.com/od/delphitips2009/qt/delphi-get-wan-ip-address-behind-router-gateway-proxy.htm

Quote From the site:


 

 function GetHTML(const AURL: string): string;
 var
   sHead,sHost,sPage: string;
   x,xCnt,xCntTotal: integer;
   sock: TClientSocket;
   ws: TWinSocketStream;
   ss: TStringStream;
   buff: array[0..4095] of char;
 const
   CrLf = #13#10;
 begin
   Result := '';

   sHost := AURL;
   x := Pos('//',sHost) ;
   if x > 0 then
     System.Delete(sHost,1,x+1) ;
   x := Pos('/',sHost) ;
   if x > 0 then
   begin
     sPage := Copy(sHost,x,Length(sHost)) ;
     System.Delete(sHost,x,Length(sHost)) ;
   end
   else
   begin
     sPage := '/';
   end;

   sock := TClientSocket.Create(nil) ;
   try
     try
       sock.ClientType := ctBlocking;
       sock.Port := 80;
       sock.Host := sHost;
       sock.Open;

       // set timeout to 20 seconds
       ws := TWinSocketStream.Create(sock.Socket,20000) ;
       ss := TStringStream.Create('') ;
       try
         sHead := 'GET ' + sPage + ' HTTP/1.0 ' + CrLf + 'Host: ' + sHost + CrLf + CrLf;
         StrPCopy(buff,sHead) ;

         ws.Write(buff,Length(sHead) + 1) ;
         ws.Position := 0;

         FillChar(buff,SizeOf(buff),0) ;
         repeat
           xCnt := ws.Read(buff,SizeOf(buff)) ;
           xCntTotal := xCntTotal + xCnt;
           ss.Write(buff[0],xCnt) ;
         until xCnt = 0;

         Result := ss.DataString;
       finally
         ws.Free;
         ss.Free;
       end;
     except
   end;
   finally
     sock.Free;
   end;
 end;
 function GetRealIp() : String;
 var
  __StringList : TStringList;
   ip: string;
 begin
    __StringList := TStringList.Create;
   try
     __StringList.Text := GetHTML('www.whatismyip.com/automation/n09230945.asp') ;
     if __StringList.Count > 0 then
     begin
      ip := __StringList.Strings[__StringList.Count - 1];
     end
     else
     begin
      ip := '';
     end;
    except
      ip := '';
    end;
    __StringList.Free;
    Result := ip;
 end;
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 4

Expert Comment

by:fromer
ID: 35688938
You will just Call GetRealIp function to get the ip...
0
 
LVL 4

Expert Comment

by:fromer
ID: 35688977
and one more thing :)...

 uses ScktComp;

add this after implementation part of your unit ...


 
0
 
LVL 4

Expert Comment

by:fromer
ID: 35689359
and the last thing :)..
if you insist on using TIdHttp

here is the working very simple code

ShowMessage(IdHTTP1.Get('http://www.whatismyip.com/automation/n09230945.asp'));

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

839 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