gpt4 book ai didi

delphi - Delphi中获取本地IP地址

转载 作者:行者123 更新时间:2023-12-03 15:04:20 33 4
gpt4 key购买 nike

Possible Duplicate:
Delphi, How to get all local IPs?

在 Delphi 2009 中不使用第 3 方组件获取计算机本地 IP 地址的最简单、最快捷的方法是什么?谢谢。

最佳答案

来自:http://www.scalabium.com/faq/dct0037.htm

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Winsock;

Function GetIPAddress():String;
type
pu_long = ^u_long;
var
varTWSAData : TWSAData;
varPHostEnt : PHostEnt;
varTInAddr : TInAddr;
namebuf : Array[0..255] of char;
begin
If WSAStartup($101,varTWSAData) <> 0 Then
Result := 'No. IP Address'
Else Begin
gethostname(namebuf,sizeof(namebuf));
varPHostEnt := gethostbyname(namebuf);
varTInAddr.S_addr := u_long(pu_long(varPHostEnt^.h_addr_list^)^);
Result := 'IP Address: '+inet_ntoa(varTInAddr);
End;
WSACleanup;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption := GetIPAddress;
end;

end.

关于delphi - Delphi中获取本地IP地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1143114/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com