2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,3 +1,4 @@
DNS is an internet service that maps domain names, like <code>rosettacode.org</code>, to IP addresses, like <code>66.220.0.231</code>.
Use DNS to resolve <code>www.kame.net</code> to both IPv4 and IPv6 addresses. Print these addresses.
<br><br>

View file

@ -1,21 +1,38 @@
:: DNS Query Task from Rosetta Code Wiki
:: Batch File Implementation
@echo off
setlocal enabledelayedexpansion
set "Temp_File=%TMP%\NSLOOKUP_%RANDOM%.TMP"
set "Domain=www.kame.net"
echo.Domain: %Domain%
set "domain=www.kame.net"
echo DOMAIN: "%domain%"
echo.
echo.IP Addresses:
::The Main Processor
nslookup %Domain% >"%Temp_File%" 2>nul
for /f "tokens=*" %%A in (
'findstr /B /C:"Address" "%Temp_File%" ^& findstr /B /C:" " "%Temp_File%"'
) do (
set data=%%A
echo.!data:*s: =!|findstr /VBC:"192.168." /VBC:"127.0.0.1"
)
del /Q "%Temp_File%"
call :DNS_Lookup "%domain%"
echo.
pause
exit /b
::Main Procedure
::Uses NSLOOKUP Command and a Temporary File
::Also uses a dirty "parsing" to detect IP addresses.
:DNS_Lookup [domain]
setlocal enabledelayedexpansion
for /f "delims=" %%T in ('forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(0x09"') do set "TAB=%%T"
set "temp_file=%TMP%\NSLOOKUP_%RANDOM%.TMP"
set "record="
for /f "tokens=1* delims=:" %%x in ('nslookup "%~1" 2^>nul') do (
set "line=%%x"
if "!line:~0,4!"=="Name" set "record=yes"
if "!line:~0,5!"=="Alias" set "record="
if "!record!"=="yes" (
if "%%y"=="" (echo %%x>>"%temp_file%") else (echo %%x:%%y>>"%temp_file%")
)
)
if exist "%temp_file%" (
for /f "tokens=*" %%a in (
'findstr /BC:"Address" "%temp_file%" ^& findstr /BC:"%TAB%" "%temp_file%"'
) do (set "data=%%a"&echo !data:*s: =!)
del /q "%temp_file%"
) else (echo Connection to domain failed.)
goto :EOF

View file

@ -0,0 +1,20 @@
#include <boost/asio.hpp>
#include <iostream>
int main() {
int rc {EXIT_SUCCESS};
try {
boost::asio::io_service io_service;
boost::asio::ip::tcp::resolver resolver {io_service};
auto entries = resolver.resolve({"www.kame.net", ""});
boost::asio::ip::tcp::resolver::iterator entries_end;
for (; entries != entries_end; ++entries) {
std::cout << entries->endpoint().address() << std::endl;
}
}
catch (std::exception& e) {
std::cerr << e.what() << std::endl;
rc = EXIT_FAILURE;
}
return rc;
}

View file

@ -0,0 +1,16 @@
MODULE DNSQuery;
IMPORT
IO:Address,
Out := NPCT:Console;
PROCEDURE Do() RAISES Address.UnknownHostException;
VAR
ip: Address.Inet;
BEGIN
ip := Address.GetByName("www.kame.net");
Out.String(ip.ToString());Out.Ln
END Do;
BEGIN
Do;
END DNSQuery.

View file

@ -1,17 +1,16 @@
/*REXX program displays IPv4 and IPv6 addresses for a supplied domain name.*/
trace off /*don't show PING none─zero return code*/
/*REXX program displays IPV4 and IPV6 addresses for a supplied domain name.*/
parse arg tar . /*obtain optional domain name from C.L.*/
if tar=='' then tar='www.kame.net' /*Not specified? Then use the default.*/
tempFID='\TEMP\DNSQUERY.$$$.' /*define temp file to store the IPv4. */
pingOpts='-l 0 -n 1 -w 1' tar /*define options for the PING command. */
do j=4 to 6 by 2 /*handle IPv4 and IPv6 addresses. */
'PING' (-j) pingOpts ">" tempFID /*restrict PING's output to a minimum. */
q=charin(tempFID,1,999) /*read the output file from PING cmd.*/
parse var q '[' IPA ']' /*parse IP address from the output. */
say 'IPv'j 'for domain name ' tar " is " IPA /*IPv4 or IPv6 address.*/
call lineout tempFID /* ◄──┬─◄ needed by some REXXes to */
end /*j*/ /* └─◄ force file integrity.*/
'ERASE' tempFID /*clean up (delete) the temporary file.*/
if tar=='' then tar= 'www.kame.net' /*Not specified? Then use the default.*/
tFID = '\TEMP\DNSQUERY.$$$' /*define temp file to store IPV4 output*/
pingOpts= '-l 0 -n 1 -w 0' tar /*define options for the PING command. */
trace off /*don't show PING none─zero return code*/
/* [↓] perform 2 versions of PING cmd.*/
do j=4 to 6 by 2 /*handle IPV4 and IPV6 addresses. */
'PING' (-j) pingOpts ">" tFID /*restrict PING's output to a minimum. */
q=charin(tFID, 1, 999) /*read the output file from PING cmd.*/
parse var q '[' ipaddr "]" /*parse IP address from the output. */
say 'IPV'j "for domain name " tar ' is ' ipaddr /*IPVx address.*/
call lineout tFID /* ◄──┬─◄ needed by some REXXes to */
end /*j*/ /* └─◄ force (TEMP) file integrity.*/
/*stick a fork in it, we're all done. */
'ERASE' tFID /*clean up (delete) the temporary file.*/