获取本地计算机的名称和IP地址
2008-10-13 12:54
218 查看
uses WinSock;
function Pub_GetComputerName: string; {计算机名}
var
CNameBuffer: PChar;
fl_loaded: Boolean;
CLen: ^DWord;
begin
result := '';
GetMem(CNameBuffer, 255);
New(CLen);
CLen^ := 255;
fl_loaded := GetComputerName(CNameBuffer, CLen^);
if fl_loaded then
result := StrPas(CNameBuffer)
else
result := 'Unkown';
FreeMem(CNameBuffer, 255);
Dispose(CLen);
end;
function Pub_LocalIP: string; {获取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;
begin
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^[I] <> nil do begin
result := StrPas(inet_ntoa(pptr^[I]^));
Inc(I);
end;
WSACleanup;
end;
function Pub_GetComputerName: string; {计算机名}
var
CNameBuffer: PChar;
fl_loaded: Boolean;
CLen: ^DWord;
begin
result := '';
GetMem(CNameBuffer, 255);
New(CLen);
CLen^ := 255;
fl_loaded := GetComputerName(CNameBuffer, CLen^);
if fl_loaded then
result := StrPas(CNameBuffer)
else
result := 'Unkown';
FreeMem(CNameBuffer, 255);
Dispose(CLen);
end;
function Pub_LocalIP: string; {获取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;
begin
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^[I] <> nil do begin
result := StrPas(inet_ntoa(pptr^[I]^));
Inc(I);
end;
WSACleanup;
end;
相关文章推荐
- 获取本地计算机的名称和IP地址
- c#中获取cpu序列号、网卡mac地址、ip地址、硬盘序列号、登录用户名、pc类型、计算机名称、物理内存
- Delphi 如何获取本地计算机名和IP地址
- Delphi 如何获取本地计算机名和IP地址
- C# 实现的本地IP地址, 计算机名称, MAC地址 和 硬盘序列号 CPU序列号 的小程序
- c#中获取cpu序列号、网卡mac地址、ip地址、硬盘序列号、登录用户名、pc类型、计算机名称、物理内存
- c#中获取cpu序列号、网卡mac地址、ip地址、硬盘序列号、登录用户名、pc类型、计算机名称、物理内存
- flex 通过js获取ip地址和计算机名称表现在ie中,为什么要对ie的安全级别设置?
- c#中获取cpu序列号、网卡mac地址、ip地址、硬盘序列号、登录用户名、pc类型、计算机名称、物理内存 【转载】
- 获取本地计算机名和IP地址
- c#中获取cpu序列号、网卡mac地址、ip地址、硬盘序列号、登录用户名、pc类型、计算机名称、物理内存
- 使用InetAddress类获取本地计算机的IP地址和主机名
- C#中获取CPU序列号、网卡Mac地址、IP地址、硬盘序列号、登录用户名、PC类型、计算机名称、物理内存,Singleton模式
- 获取硬件信息的delphi源码(CPUID、操作系统、Mac物理地址、计算机名称、IP地址、用户名)
- 如何在.net中获取电脑名称,IP地址,用户名,计算机所在域名(转载)
- 获取本地计算机名和IP地址
- API函数 获取ip地址,计算机名称,当前用户名称
- c#中获取cpu序列号、网卡mac地址、ip地址、硬盘序列号、登录用户名、pc类型、计算机名称、物理内存 【转载】
- 获取多网卡IP地址(D7~XE5)和本机计算机名称
- C#中获取CPU序列号、网卡Mac地址、IP地址、硬盘序列号、登录用户名、PC类型、计算机名称、物理内存