WEB开发网
开发学院软件开发Delphi 如何得到本机的ip地址! 阅读

如何得到本机的ip地址!

 2006-02-04 13:26:13 来源:WEB开发网   
核心提示:PRogram get_ip;useswinsock,sysutils;VARch : ARRAY[1..32] OF Char;i : Integer;WSData: TWSAData;MyHost: PHostEnt;beginIF WSAstartup(2,wsdata)<>0 THENBEGINWr
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.

Tags:如何 得到 本机

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接