📄 unit1.~pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Winsock, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Label1: TLabel;
Memo1: TMemo;
Label2: TLabel;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Function GetHostName(strIPAddress : String) : String;
Var
strHost : String ;
pszIPAddress : PChar;
pReturnedHostEnt : PHostEnt;
InternetAddr : u_long;
GInitData : TWSADATA;
Begin
strHost := '';
If WSAStartup($101, GInitData) = 0 then
Begin
pszIPAddress := StrAlloc( Length( strIPAddress ) + 1 );
StrPCopy( pszIPAddress, strIPAddress );
InternetAddr := Inet_Addr(pszIPAddress);
StrDispose( pszIPAddress );
pReturnedHostEnt := GetHostByAddr( PChar(@InternetAddr),4, PF_INET );
try
strHost := pReturnedHostEnt^.h_name;
WSACleanup;
Result := strHost
except
Result := 'Host inv醠ido ou n鉶 encontrado';
end;
end;
end;
Function GetIP(WebHostName:string):string;
var
WSAData: TWSAData;
HostEnt: PHostEnt;
begin
WSAStartup(2, WSAData);
//Gethostname(PChar(WebHostName), 255);
//SetLength(WebHostName, StrLen(PChar(WebHostName)));
HostEnt := gethostbyname(PChar(WebHostName));
with HostEnt^ do
begin
Result := Format('%d.%d.%d.%d',
[Byte(h_addr^[0]),Byte(h_addr^[1]),
Byte(h_addr^[2]),Byte(h_addr^[3])]);
end;
WSACleanup;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
memo1.Lines.Add(edit1.Text+' - '+getip(edit1.Text));
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
begin
button1.Click;
edit1.Clear;
edit1.SetFocus;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
memo1.Clear;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -