Real IP

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
wackyteseoAsked:
Who is Participating?
 
fromerCommented:
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
 
TheMakCommented:
Directly open http://www.whatismyip.com/ website and you will see on the top your Real IP address.

Regards,
0
 
Mahdi78Commented:
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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
fromerCommented:
You will just Call GetRealIp function to get the ip...
0
 
fromerCommented:
and one more thing :)...

 uses ScktComp;

add this after implementation part of your unit ...


 
0
 
fromerCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.