本机IP怎么获得,特别是多网卡的情况下。多个IP都要查出来。
解决方案 »
- 关于Virtual Treeview 问题
- 由于请不到那么多天的假,不对不把买来的火车票出售(广州--南京)k222车次1张
- 如何用高级语言如delphi做mapinfo的二次开发,多谢各位了!
- 如何设置TTS把文件生成语音文件的格式
- 在图像上动态生成数据的问题,急!!!请大虾们帮忙呀。。
- 急--急--急,请高手帮忙写此函数。
- 怎样让DBGrid暂时不随数据源刷新?
- 诸位大侠,怎样得到‘001234501’中从第一个不为零的数字之前‘0’的个数。谁能给编个函数
- 为什么用close不能完全关闭程序,程序占用的资源为什么不能释放完全。
- 请问,在Paradox表中,有关日期型字段记录如何查询?
- 一个有关检索数据库的问题
- 俩小问题,但我始终想不出来,请帮忙看看!
procedure TForm1.Button1Click(Sender: TObject);
var
Ip:string;
Ipstr:string;
buffer:array[1..32] of char;
i:integer;
WSData:TWSAData;
Host:PHostEnt;
begin
if WSAstartup(2,WSData)<>0 then //为程序使用WS2_32.DLL初始化
begin
showmessage('WS2_32.DLL初始化失败!');
halt;
end;
try
if gethostname(@buffer[1],32)<>0 then
begin
showmessage('没有得到主机名!');
halt;
end;except
showmessage('没有成功返回主机名');
halt;
end;
Host:=gethostbyname(@buffer[1]);
if Host=nil then
begin
showmessage('IP地址为空!');
halt;
end
else
begin
edit2.text:=host.h_name;
edit3.text:=chr(host.h_addrtype+64);
for i:=1 to 4 do
begin
Ip:=inttostr(Ord(Host.h_addr^[i-1]));
showmessage('分段Ip地址为:'+Ip);
Ipstr:=Ipstr+Ip;
if i<4 then
Ipstr:=Ipstr+'.'
else
edit1.text:=Ipstr;
end;
end;
end;end.
//WSAstartup在使用gethostname,gethostbyname前
//一定不要忘了初始化WS2_32.DLL
function LocalIP1 : 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
result:=StrPas(inet_ntoa(pptr^[I]^));
Inc(I);
end;
WSACleanup;
end;
function getRemoteIP:string;//获取远程IP地址
var
wsdata:Twsadata;
PCName : array[0..128] of char;
begin
Wsastartup($101,wsdata);
GetHostName(@PCName,128);
result := iNet_ntoa(PInAddr(GetHostByName(@PCName)^.h_addr_list^)^);
WSACleanup;
end;