如何得到本机的ip地址!
敬业的IT人
互联网
佚名
2008-1-4 16:29:51
program get_ip;
uses
winsock,sysutils;
VAR
ch : ARRAY[1..32] OF Char;
i : Integer;
WSData: TWSAData;
MyHost: PHostEnt;
begin
IF WSAstartup(2,wsdata)<>0 THEN
BEGIN
Writeln('can't start Winsock: Error ',WSAGetLastError);
Halt(2);
END;
try
IF getHostName(@ch[1],32)<>0 THEN
BEGIN
Writeln('getHostName failed');
Halt(3);
END;
except
Writeln('getHostName failed');
halt(3);
end;
MyHost:=GetHostByName(@ch[1]);
IF MyHost=NIL THEN
BEGIN
Writeln(GetHostName(' StrPas(@ch[1]) ') failed : Error
' IntToStr(WSAGetLastError));
Halt(4);
END
ELSE
BEGIN
Write('address ');
FOR i:=1 TO 4 DO
BEGIN
Write(Ord(MyHost.h_addr^[i-1]));
IF i<4 THEN
write('.')
ELSE
writeln;
END;
END;
end.
uses
winsock,sysutils;
VAR
ch : ARRAY[1..32] OF Char;
i : Integer;
WSData: TWSAData;
MyHost: PHostEnt;
begin
IF WSAstartup(2,wsdata)<>0 THEN
BEGIN
Writeln('can't start Winsock: Error ',WSAGetLastError);
Halt(2);
END;
try
IF getHostName(@ch[1],32)<>0 THEN
BEGIN
Writeln('getHostName failed');
Halt(3);
END;
except
Writeln('getHostName failed');
halt(3);
end;
MyHost:=GetHostByName(@ch[1]);
IF MyHost=NIL THEN
BEGIN
Writeln(GetHostName(' StrPas(@ch[1]) ') failed : Error
' IntToStr(WSAGetLastError));
Halt(4);
END
ELSE
BEGIN
Write('address ');
FOR i:=1 TO 4 DO
BEGIN
Write(Ord(MyHost.h_addr^[i-1]));
IF i<4 THEN
write('.')
ELSE
writeln;
END;
END;
end.
- 最新文章
- 一个新算法的表达式求值的函数[01-04]
- 创建不规则形状的Control[01-04]
- 一个C 程序员的Delphi学习笔记[01-04]
- Delphi7的IDE概述(二)[01-04]
- Delphi编程规范1.0.0.0[01-04]
- 发送电子邮件[01-04]
- 相关文章
- 解析IP地址为主机域名[01-04]
- 解析IP地址为主机域名。[01-04]
- 获得机器IP地址[01-04]
- 如何用C++编程获得某台机器的IP地址?[01-03]
- Windows Vista系统下如何查看IP地址[01-03]
- Win 2003网络适配器的IP地址[01-03]
