1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
function TFServer.GetLocalIp: string;
var
HTMLSource:string;
wsaData: TWSAData;
addr: TSockAddrIn;
Phe: PHostEnt;
szHostName: array[0..128] of Char;
BeginDelimit,EndDelimit:integer;
begin
if Radiobutton1.Checked then
begin
try
try
if WSAStartup($101, WSAData) <> 0 then
raise Exception.Create('Cannot initialize WSA');
try
if GetHostName(szHostName, 128) <> SOCKET_ERROR then
begin
Phe := GetHostByName(szHostName);
if Assigned(Phe) then
begin
addr.sin_addr.S_addr := longint(plongint(Phe^.h_addr_list^)^);
Result := inet_ntoa(addr.sin_addr);
end;
end;
finally
WSACleanup;
end;
except
on e:Exception do begin
Result:='Error: '+e.Message;
raise;
end else
raise;
end;
finally
//StaticText1.Caption:='Automatic Ip detection: '+Result;
end;
end;
if Radiobutton2.Checked then
begin
Try
HTMLSource:=IdHTTP1.Get('http://checkip.dyndns.org/'); //http://www.adresseip.com http://checkip.dyndns.org/
delete(HTMLSource,1,pos(':',HTMLSource)+1);
delete(HTMLSource,pos('<',HTMLSource),80);
result:=HTMLSource;
Except
// Result:=false;
end;
end;
if Radiobutton3.Checked then
Try
result:=IdHTTP1.Get('http://filezilla.sourceforge.net/misc/ip.php');
Except
// Result:=false;
end;
if Radiobutton4.Checked then
begin
Try
HTMLSource:= IdHTTP1.Get('http://www.showmyip.com/fr/'); //http://www.showmyip.com/fr/On demande le contenu de la page et on le récupère dans HTMLSource
BeginDelimit:=length(Copy(HTMLSource,1, Pos('INTERNET',HTMLSource)+ 9 ) );//);76 ,77
EndDelimit:=length(Copy(HTMLSource,Pos('-->',HTMLSource)-1,Length(HTMLSource)));
Result:=Copy(HTMLSource,BeginDelimit,Length(HTMLSource)-BeginDelimit-EndDelimit+1); //On extrait l'adresse IP de HTMLSource
Except
// Result:=false;
end;
end;
IPServer2.Text:= 'Votre IP actuel est http://' +Result;//'Automatic Ip detection: '
IPServer.Text:= Result ;//'Automatic Ip detection: '
//if IPServer.Text= Result then Rbsite.checked :=true;
end; |
Partager