⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit2.pas

📁 《Delphi百例》源码?禗elphi百例》源码
💻 PAS
字号:
unit Unit2;

interface

uses
  Classes,winsock,sysutils,windows;

type
  convert = class(TThread)
  private
    { Private declarations }
  protected
    procedure Execute; override;
  end;

implementation
uses unit1;

function GetIP(Name:string) : string;
//根据IP地址获取对方计算机名函数
type
TaPInAddr = array [0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe :PHostEnt;
pptr : PaPInAddr;
I : Integer;
GInitData : TWSADATA;
begin
  WSAStartup($101, GInitData);
  Result := '';
  phe :=GetHostByName(pchar(Name));
  pptr := PaPInAddr(Phe^.h_addr_list);
  result:=StrPas(inet_ntoa(pptr^[0]^));
  WSACleanup;
end;

function GetDomainName(Ip:string):string;
//根据计算机名获取IP地址函数
var 
pH:PHostent;
data:twsadata;
ii:dword;
begin
  WSAStartup($101, Data);
  ii:=inet_addr(pchar(ip));
  pH:=gethostbyaddr(@ii,sizeof(ii),PF_INET);
  if (ph<>nil) then
  result:=pH.h_name
  else
  result:='';
  WSACleanup();
end;

procedure convert.Execute;
var i:integer;temp:string;comp:boolean;
begin
temp:=form1.Edit1.Text;
comp:=false;
for i:=1 to length(temp) do
   begin
   if ((temp[i]>'9') or (temp[i]<'0')) and (temp[i]<>'.') then begin//看是否是IP
      form1.Button1.Caption:='终止';
       Form1.Edit1.Text:=GetIp(temp);
       comp:=true;
      Form1.Button1.Caption:='转化';
   end;
 if comp then break;
end;
if not comp then
  begin
      form1.Button1.Caption:='终止';
      Form1.Edit1.Text:=GetDomainName(temp);
      Form1.Button1.Caption:='转化';
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -