delphi获取Ip

procedure TForm1.Button1Click(Sender: TObject);
var
   aName: array[0..100] of char;
   WSData: Twsadata;
   a1, a2, a3, a4: byte;
   p: PHostEnt;
   Comput,
   ip: String;
begin
  WSAStartup(1,WSData);
  try
     GetHostName(aName,   100);
     p:=GetHostByName(aName);
     Char(a1):=p.h_addr_List^[0];
     Char(a2):=p.h_addr_List^[1];
     Char(a3):=p.h_addr_List^[2];
     Char(a4):=p.h_addr_List^[3];
  finally
     WSACleanup;
  end;
  Comput:=string(aName);  {计算机名}
  IP:=IntToStr(a1)+'.'+IntToStr(a2)+'.'+IntToStr(a3)+'.'+IntToStr(a4);
  Label1.Caption := ip;
end;

你可能感兴趣的:(职场,休闲)