PHP implementation of DNS domain name Query method detailed (graphic)

Source: Internet
Author: User
Tags echo date php regular expression
This article introduces the implementation of PHP with a section of the query DNS domain name information code, there is a need for a friend reference.

In PHP, domain-related operations typically use two functions, namely: gethostbyname () and gethostbyaddr ().

One, the IP address query gethostbyname () function, which can be used to find the IP address of a given domain name. GetHostByName () Returns a pointer to the hostent structure that contains the host name and address information for the given host name.

String gethostbyname (string hostname) parameter: hostname, which does not require http://, for example, bbs.it-home.org. This function returns the IP address (IP address) of a machine name (Domain name). If the execution fails, the original machine name is returned.

Second, the domain name query

GETHOSTBYADDR returns the machine name.

Syntax: String gethostbyaddr (string ip_address);

return value: String

Function Type: Network system

Content Description

This function returns the machine name (Domain name) for an IP address. If the execution fails, the original IP address is returned.

Third, the example of the following code to implement the domain name IP address and domain name query, is a good example.

     * Lookup Failed * '; Get submitted host/domain name $DN = isset ($_request[' dn ")? $_request[' DN ']: '; if ($dn = = $prompt _dn) {$dn = ";}//Get submitted IP address $ip = isset ($_request[' IP '])? $_request[' IP ']: '; if ($ip = = $prompt _ip) {$ip = ';}//Check if host/domain name specified if ($DN) {//domain name specified;     P Address Lookup Request if ($dn = = ' me ') {$ip = $_server[' remote_addr ');         } else {//Lookup IP address by domain/host name $ip = @gethostbyname ($DN);         if ($ip = = $dn) {$ip = $lookupfail; }} $message = $prompt _dn. ". $dn. ':: '. $prompt _ip. ' '. $ip; }//Check if IP address specified else if ($IP) {//Lookup domain/host name by IP address $DN = @gethostbyad     Dr ($ip); Check Lookup if ($dn = = $ip) {//IP address invalid or domain name not found $DN = $lookupfail     ; } $message = $prompt _ip. ' '. $ip. ':: '. $prompt _dn. $Dn } else {$message = $prompt _dn. '. $_server[' Http_host ']. ':: '. $prompt _ip. ' '. $_server[' server_addr ';  }?>  <title><?php echo $pagetitle;? ></title>   

Welcome to Copyright©2003-by Programmer's house!

The above code, illustrated: You may be interested in the article: PHP get the domain name of several global variables php from the URL to get the instance code of the domain name of PHP to obtain the site of the route domain name method discussion: PHP get domain name and domain name IP address method PHP Gets the code of the domain name in the URL a sample PHP matches the code of the domain name in the URL php gets the current URL and the code of the domain name PHP regular expression matches the domain name in the URL PHP call million network interface implementation of the domain name query function

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.