Delphi中根据IP地址得到主机名
本实例演示如何利用TUdpSocket组件获取IP地址和主机名。向窗体上添加一个TUdpSocket组件,如图1所示。
<喎?http://www.zzzyk.com/kf/ware/vc/" target="_blank" class="keylink">vc3Bhbj48YnIvPg0KICAgICAgICAgICAgzbwxINb3vefD5jwvZGl2Pg0KICAgICAgICAgICAgPC90ZD4NCiAgICAgICAgPC90cj4NCiAgICA8L3Rib2R5Pg0KPC90YWJsZT4NCjxici8+DQqhoaGhVFVkcFNvY2tldNfpvP7W0NPQwb249sr00NQmbWRhc2g7Jm1kYXNoO0xvY2FsSG9zdE5hbWW6zUxvY2FsSG9zdEFkZHKjrMbk1tC31rHwtOa0osHLsb612LzGy+O7+rXE1ve7+sP7us1JULXY1rejrMv50tTU2rSwzOW1xLP1yry7r9bQzO2808jnz8LP7NOmtPrC68C0z9TKvtb3u/rD+7rNSVC12Na3o7ogPGJyLz4NCjxici8+DQo8dGFibGUgYm9yZGVyY29sb3I9"#ffcc66" width="90%" align="center" bgcolor="#e3e3e3" border="1">
procedure TForm1.FormCreate(Sender: TObject); |
begin self.Caption:=UdpSocket1.LocalHostName; self.Caption:=self.Caption+’:’+UdpSocket1.LocalHostAddr; end; |
程序代码如下:
unit Unit1; inte易做图ce uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Sockets, ExtCtrls; type TForm1 = class(TForm) UdpSocket1: TUdpSocket; procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin self.Caption:=UdpSocket1.LocalHostName; self.Caption:=self.Caption+’:’+UdpSocket1.LocalHostAddr; end; end. |
保存文件,然后按F9键运行程序,程序运行结果如图2所示。
补充:软件开发 , Delphi ,