标题:获取IP地址,在XP中运行正常可以正常读取拨号IP,在WIN7中却无法读拨号IP而 ...
只看楼主
rogersgb
Rank: 1
等 级:新手上路
帖 子:73
专家分:0
注 册:2016-2-3
结帖率:47.37%
 问题点数:0 回复次数:0 
获取IP地址,在XP中运行正常可以正常读取拨号IP,在WIN7中却无法读拨号IP而读取本地网卡IP,为什么?
//获取IP地址
Function GetLocalIp(InternetIP:boolean):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;
     IP: String;
begin
     Screen.Cursor := crHourGlass;
     try
       WSAStartup($101, GInitData);
       IP:='0.0.0.0';
       GetHostName(Buffer, SizeOf(Buffer));
       phe := GetHostByName(buffer);
       if phe = nil then
       begin
         ShowMessage(IP);
         Result:=IP;
         Exit;
       end;
       pPtr := PaPInAddr(phe^.h_addr_list);
       if InternetIP then
         begin
           I := 0;
           while pPtr^[I] <> nil do
             begin
               IP := inet_ntoa(pptr^[I]^);
               Inc(I);
             end;
         end
       else
         IP := inet_ntoa(pptr^[0]^);
       WSACleanup;
       Result:=IP;//如果上网则为上网ip否则是网卡ip
     finally
       Screen.Cursor := crDefault;
     end;
end;

//Showmessage(GetLocalIp(true));

[此贴子已经被作者于2017-10-10 13:10编辑过]

搜索更多相关主题的帖子: 获取 IP 读取 begin end 
2017-10-10 12:59



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-481234-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016414 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved