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.

  • 相关阅读:
    页面整体布局思路
    CSS3转换、过渡、动画效果及css盒子模型
    CSS随笔
    CSS基础,认识css样式
    HTML基础表单
    HTML基础
    java.sql.SQLException: 调用中无效的参数DSRA0010E: SQL 状态 = null,错误代码 = 17,433
    There is no Action mapped for namespace / and action name accredit.
    myeclipse开启后卡死、building workspace缓慢 问题解决
    you need to upgrade the working copy first
  • 原文地址:https://www.cnblogs.com/onionhacker/p/3437583.html
Copyright © 2011-2022 走看看