uses WinSock;
取机器名:
function ComputerName : String;
var
CNameBuffer : PChar;
fl_loaded : Boolean;
CLen : ^DWord;
begin
GetMem(CNameBuffer,255);
New(CLen);
CLen^:= 255;
fl_loaded := GetComputerName(CNameBuffer,CLen^);
if fl_loaded then
ComputerName := StrPas(CNameBuffer)
else
ComputerName := 'Unkown';
FreeMem(CNameBuffer,255);
Dispose(CLen);
end;
取本机所有IP地址
function GetLocalIP : string;
//获得本机的IP地址,返回值为所找到的IP地址
//每一行一个IP地址
type
TaPInAddr = array [0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe : PHostEnt;
pptr : PaPInAddr;
Buffer : array [0..63] of char;
I : Integer;
GInitData : TWSADATA;
Addr : String;
begin
//result:='218.72.19.148';
//exit;
try
Addr:='';
WSAStartup($101, GInitData);
Result := '';
GetHostName(Buffer, SizeOf(Buffer));
phe :=GetHostByName(buffer);
if phe = nil then Exit;
pptr := PaPInAddr(Phe^.h_addr_list);
I := 0;
while pptr^ <> nil do begin
Addr:=Addr+#0+StrPas(inet_ntoa(pptr^^));
Inc(I);
end;
WSACleanup;
finally
if pos('127.0.0.1',Addr)<1 then
Addr:=Addr+#0+'127.0.0.1';
Delete(Addr, 1 ,1);
result:=copy(Addr,1,pos(#0,addr)-1);
end;
end;