What is DNS?
DNS is stand for Domain Name System (or Service or Server), an Internet service that translates domain names into IP addresses. Because domain names are alphabetic, they are easier to remember. The Internet however, is really based on IP addresses. Every time you use a domain name, therefore, a DNS service must translate the name into the corresponding IP address. For example, the domain name http://www.example.com might translate to 10.0.154.2
Hardware
- PHPoC Blue (+ USB WLAN) or PHPoC Black (+ Ethernet cable)
- Micro USB to USB Cable (to upload source code to PHPoC Device)
Quick Steps
Source code of this example is a part of PHPoC Support Packet (PSP). You need to:
- Download PHPoC Support Package.
- Upload example\net\01.php_task\dns_lookup to PHPoC Blue/Black.
- Modify the Domain Name as you want in task0.php
- Save the modified file.
- Configure network parameters (e.g. WiFi SSID, password, IP address ...).
Source Code
Source files includes:
- init.php: this file is run when PHPoC system is powered or reset. It is used to specify which file is run is system loop.
- task0.php: this file is run in system loop of PHPoC devices.
init.php
This file is run when PHPoC system is powered or reset. It is used to specify that task0.php is run is system loop.
PHP Code:
<?php
system("php task0.php");
?>
task0.php
[Full Code]
PHP Code:
<?php
if(_SERVER("REQUEST_METHOD"))
exit; // avoid php execution via http request
include_once "/lib/sn_dns.php";
echo "PHPoC example : get ip address by host name\r\n";
dns_setup(0, "");
$host_name = "www.google.com";
$host_addr = dns_lookup($host_name, RR_A);
if($host_addr == $host_name)
echo "$host_name : Not Found\r\n";
else
echo "$host_name : $host_addr\r\n";
?>
[Explanation]
Source code of this file does:
- Perform DNS lookup to translate domain names of TCP server into IP addresses.
- Print hostname and IP address to PHPoC debugger console.
Test and Result
- Click "Run" button on PHPoC Debugger.
- See Result on PHPoC Debugger's Console.
See Also
- Sending email (SMTP)
- Sending email (ESMTP)
- MySQL - Inserting Data to Remote Server
- MySQL - Updating Data to Remote Server
- TCP Server - Single TCP Connection
- TCP Server - Multiple TCP Connections
- TCP Client - HTTP GET
Other Resources