salut,
dans le programme WEBCam IP j'ai mis une fonction qui récupère l'IP (il y a 4 possibilités):
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/');
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/'); //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;
IPServer.Text:=Result;//'Automatic Ip detection: '
end;
Il y en a peut être une qui fonctionne sous D4 mais je n'ai pas testé
@+
jlen
|