MENU
IP Address
checkdnsrr($s1 [,$s2=”MX”]) or dns_check_record($s1 [,$s2=”MX”]) searches DNS for records of type $s2 corresponding to host $s1. $s2 can be A, MX, NS, SOA, PTR, CNAME, AAAA, A6, SRV, NAPTR, TXT or ANY. TRUE is returned if any records are found.getmxrr($s, &$arr1 [,&$arr2]) or dns_get_mx($s, &$arr1 [,&$arr2]) searches DNS for MX records corresponding to host $s and stores them in $arr1. $arr2 stores the weight information.
dns_get_record($s [, $i=DNS_ANY [, &$arr1 [, &$arr2 [, &$b=false]]]]) returns an associative array of DNS Resource Records associated with the host $s. $i specifies the type and can be DNS_A, DNS_CNAME, DNS_HINFO, DNS_MX, DNS_NS, DNS_PTR, DNS_SOA, DNS_TXT, DNS_AAAA, DNS_SRV, DNS_NAPTR, DNS_A6, DNS_ALL or DNS_ANY. $arr1 stores the Resource Records for the Authoritative Name Servers. $arr2 stores Additional Records. $b specifies whether to use raw mode, in which only the requested type is queried, instead of looping type by type before going with the additional information.
<?php
echo "<pre>";
var_dump(checkdnsrr("www.google.com","A"));
var_dump(getmxrr("binarybehemoth.com",$arr));
print_r($arr);
print_r(dns_get_record("binarybehemoth.com"));
echo "</pre>";
?>bool(true)
bool(true)
Array
(
[0] => mail.binarybehemoth.com
)
Array
(
[0] => Array
(
[host] => binarybehemoth.com
[class] => IN
[ttl] => 900
[type] => MX
[pri] => 5
[target] => mail.binarybehemoth.com
)
[1] => Array
(
[host] => binarybehemoth.com
[class] => IN
[ttl] => 899
[type] => NS
[target] => ns4.no-ip.com
)
[2] => Array
(
[host] => binarybehemoth.com
[class] => IN
[ttl] => 899
[type] => NS
[target] => ns5.no-ip.com
)
[3] => Array
(
[host] => binarybehemoth.com
[class] => IN
[ttl] => 899
[type] => NS
[target] => ns2.no-ip.com
)
[4] => Array
(
[host] => binarybehemoth.com
[class] => IN
[ttl] => 899
[type] => NS
[target] => ns1.no-ip.com
)
[5] => Array
(
[host] => binarybehemoth.com
[class] => IN
[ttl] => 899
[type] => NS
[target] => ns3.no-ip.com
)
)
<?php
echo "<pre>";
echo gethostname()."\n";
echo gethostbyname('www.google.com')."\n";
print_r(gethostbynamel('www.google.com'));
echo gethostbyaddr('173.194.127.80');
echo "</pre>";
?>Phang
173.194.127.83
Array
(
[0] => 173.194.127.83
[1] => 173.194.127.84
[2] => 173.194.127.80
[3] => 173.194.127.81
[4] => 173.194.127.82
)
hkg03s11-in-f16.1e100.net
getservbyport($i,$s) returns as a string the Internet service associated with port $i and protocol $s. getservbyname($s1, $s2) returns as an integer the port number associated with the Internet service $s1 and protocol $s2.
<?php
echo "<pre>";
for ($i=0; $i<70; $i++) echo $i."(".getprotobynumber($i).")";
echo "\n".getprotobyname('tcp')."\n";
$services = array('http', 'ftp', 'ssh', 'telnet', 'imap','smtp','nicname', 'gopher', 'finger', 'pop3', 'www');
foreach ($services as $service) {
$port = getservbyname($service, 'tcp');
echo $service . ": " . $port . "\n";
}
echo getservbyport(80,'tcp');
echo "</pre>";
?>0(ip)1(icmp)2()3(ggp)4()5()6(tcp)7()8(egp)9()10()11()12(pup)13()14()15()16()17(udp)18()19()20(hmp)21()22(xns-idp)23()24()25()26()27(rdp)28()29()30()31()32()33()34()35()36()37()38()39()40()41(ipv6)42()43(ipv6-route)44(ipv6-frag)45()46()47()48()49()50(esp)51(ah)52()53()54()55()56()57()58(ipv6-icmp)59(ipv6-nonxt)60(ipv6-opts)61()62()63()64()65()66(rvd)67()68()69() 6 http: 80 ftp: 21 ssh: 22 telnet: 23 imap: 143 smtp: 25 nicname: 43 gopher: 70 finger: 79 pop3: 110 www: 80 http
ip2long($s) converts an IP address into an integer.
long2ip($i) converts an integral IP address into a string in Internet-standard dotted format.
<?php
echo "<pre>";
echo bin2hex(inet_pton('115.135.180.20'))."\n"; // packed binary shown as hex so it prints safely
echo inet_ntop(inet_pton('115.135.180.20'))."\n";
echo ip2long('115.135.180.20')."\n";
echo long2ip(1938273300)."\n";
echo "</pre>";
?>7387b414 115.135.180.20 1938273300 115.135.180.20