zoukankan      html  css  js  c++  java
  • 域名解析-delphi 源码

    unit Unit1;

    interface

    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs,winsock, Vcl.StdCtrls;

    type
      TForm1 = class(TForm)
        Edit1: TEdit;
        Edit2: TEdit;
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;

    var
      Form1: TForm1;

    implementation

    {$R *.dfm}


    function HostToIP(Name: string; var Ip: string): Boolean;   //hosttoip 函数作用是将域名解析成ip
    var
    wsdata : TWSAData;
    hostName : array [0..255] of AnsiChar;
    hostEnt : PHostEnt;
    addr : PAnsichar;
    begin
    WSAStartup ($0101, wsdata);
    try
        gethostname (hostName, sizeof (hostName));
        StrPCopy(hostName, Name);
        hostEnt := gethostbyname (hostName);
        if Assigned (hostEnt) then
          if Assigned (hostEnt^.h_addr_list) then begin
            addr := hostEnt^.h_addr_list^;
            if Assigned (addr) then begin
              IP := Format ('%d.%d.%d.%d', [byte (addr [0]),
              byte (addr [1]), byte (addr [2]), byte (addr [3])]);
              Result := True;
            end
            else
              Result := False;
          end
          else
            Result := False
        else begin
          Result := False;
        end;
    finally
        WSACleanup;
    end
    end;



    procedure TForm1.Button1Click(Sender: TObject);
    var     //定义一个字符串变量
    Temp:string;
    begin
    HostToIP(edit1.text,Temp); //将输入的域名解析成IP
    edit2.Text:=Temp; //显示在EDIT2当中

    end;

    procedure TForm1.FormCreate(Sender: TObject);
    begin

    end;

    end.

  • 相关阅读:
    Ubuntu 14.04 LTS 安装 NVIDIA 显卡驱动后的屏幕亮度调节问题
    算法算法算法
    Java transient关键字
    使用git和github管理自己的项目---基础操作学习[转]
    Linux 查看系统硬件信息[转]
    实现Servlet容器一
    nginx入门三
    nginx入门二
    nginx入门一
    centos7入门
  • 原文地址:https://www.cnblogs.com/onionhacker/p/3437583.html
Copyright © 2011-2022 走看看