DELPHI 获取本地IP地址源码


本文整理自网络,侵删。

 
uses WinSock;
 
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
    try
        WSAStartup($101,   GInitData);
        Result := '';
        GetHostName(Buffer,SizeOf(Buffer));
        phe := GetHostByName(buffer);
        if phe <> nil Then
        begin
            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;
        end;
    finally
        WSACleanup;
    end;
end;

――――――――――――――――

原文链接:https://blog.csdn.net/xxkku521/article/details/11609499

相关阅读 >>

Delphi版文件夹加密软件源代码

Delphi 日期加减

Delphi 捕捉异常:try..except..end

Delphi写的服务程序在服务管理器中显示“描述”

Delphi xe中windows7新的taskbar功能的使用

Delphi datetimepicker控件日期格式

Delphi xe10 麦克风、摄像头操作

Delphi executewait运行一个程序等待其结束

Delphi 将image组件的图片保存为jpg格式图片方法

Delphi tcombobox 设置默认值

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...