DBMNG数据库管理与应用

抓住自己最有兴趣的东西,由浅入深,循序渐进地学……
当前位置:首页 > 经验分享 > Delphi

delphi编程获取本地IP地址

参考测试了好多个网上的函数,都得不到正确的结果,最终找到一个能用的。环境:delphi5&win7

function   LocalIP   :   string;
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
            if   i=0
            then   result:=StrPas(inet_ntoa(pptr^[I]^))
            else   result:=result+ ', '+StrPas(inet_ntoa(pptr^[I]^));
            Inc(I);
        end;
        WSACleanup;
end;

本站文章内容,部分来自于互联网,若侵犯了您的权益,请致邮件chuanghui423#sohu.com(请将#换为@)联系,我们会尽快核实后删除。
Copyright © 2006-2023 DBMNG.COM All Rights Reserved. Powered by DEVSOARTECH            豫ICP备11002312号-2

豫公网安备 41010502002439号