uses winsock; ①获取本机机器名称: procedure TForm1.BitBtn1Click(Sender: TObject); var wsData:twsadata; hname:string; aname:array[0..100] of Char; begin WSAStartup(1,wsData); try gethostname(aname,100); hname:=aname; ShowMessage(hname); finally WSACleanup; end; end; ②获取本机IP地址: procedure TForm1.BitBtn2Click(Sender: TObject); var wsData:TWSAData; aName:array[0..100] of Char; p:PHostEnt; i:Integer; a1,a2,a3,a4:Byte; sStr:string; begin WSAStartup(1,wsData); try gethostname(aName,100); p:=gethostbyname(aName); i:=0; Char(a1):=p.h_addr_list^[i]; Char(a2):=p.h_addr_list^[i+1]; Char(a3):=p.h_addr_list^[i+2]; Char(a4):=p.h_addr_list^[i+3]; sStr:= IntToStr(a1)+'.'+ IntToStr(a2)+'.'+IntToStr(a3)+'.'+IntToStr(a4); ShowMessage(sStr); finally WSACleanup; end; end;