Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
21
Task/DNS-query/Batch-File/dns-query.bat
Normal file
21
Task/DNS-query/Batch-File/dns-query.bat
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
set "Temp_File=%TMP%\NSLOOKUP_%RANDOM%.TMP"
|
||||
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%"
|
||||
echo.
|
||||
pause
|
||||
48
Task/DNS-query/Cache-ObjectScript/dns-query-1.cos
Normal file
48
Task/DNS-query/Cache-ObjectScript/dns-query-1.cos
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
Class Utils.Net Extends %RegisteredObject
|
||||
{
|
||||
|
||||
ClassMethod QueryDNS(pHost As %String, Output ip As %List) As %Status
|
||||
{
|
||||
// some initialisation
|
||||
K ip S ip=""
|
||||
|
||||
// check host operating system and input parameters
|
||||
S OS=$SYSTEM.Version.GetOS()
|
||||
I '$LF($LB("Windows","UNIX"), OS) Q $$$ERROR($$$GeneralError, "Not implemented.")
|
||||
I OS="Windows" S cmd="nslookup "_pHost
|
||||
I OS="UNIX" S cmd="host "_pHost
|
||||
I $MATCH(pHost, "^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$")=0 {
|
||||
Q $$$ERROR($$$GeneralError, "Invalid host name.")
|
||||
}
|
||||
|
||||
// invoke command
|
||||
S list=##class(Utils.OS).Call(cmd, 0)
|
||||
|
||||
// iterate through list
|
||||
S ptr=0, skip=1
|
||||
WHILE $LISTNEXT(list,ptr,value) {
|
||||
I value="" CONTINUE
|
||||
I skip, OS="Windows" S skip=$S(value["Name:": 0, 1: 1) CONTINUE
|
||||
S ipv4=..GetIPAddr("ipv4", value) I $L(ipv4) S $LI(ip, 4)=ipv4
|
||||
S ipv6=..GetIPAddr("ipv6", value) I $L(ipv6) S $LI(ip, 6)=ipv6
|
||||
}
|
||||
|
||||
// finished
|
||||
I $LD(ip, 4)=0, $LD(ip, 6)=0 Q $$$ERROR($$$GeneralError, "Lookup failed.")
|
||||
QUIT $$$OK
|
||||
}
|
||||
|
||||
ClassMethod GetIPAddr(pType As %String = "", pValue As %String = "") As %String
|
||||
{
|
||||
I pType="ipv4" {
|
||||
S pos=$LOCATE(pValue, "((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.|$)){4}")
|
||||
I pos Q $P($E(pValue, pos, *), " ")
|
||||
}
|
||||
I pType="ipv6" {
|
||||
S pos=$LOCATE(pValue, "([0-9A-Fa-f]{0,4}:){2,7}([0-9A-Fa-f]{1,4}$|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4})")
|
||||
I pos Q $P($E(pValue, pos, *), " ")
|
||||
}
|
||||
QUIT ""
|
||||
}
|
||||
|
||||
}
|
||||
34
Task/DNS-query/Cache-ObjectScript/dns-query-2.cos
Normal file
34
Task/DNS-query/Cache-ObjectScript/dns-query-2.cos
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
Class Utils.OS Extends %RegisteredObject
|
||||
{
|
||||
|
||||
ClassMethod Call(cmd, echo = 1) As %List
|
||||
{
|
||||
// instatiate pipe object
|
||||
S list=""
|
||||
S pipe=##class(%File).%New(cmd)
|
||||
|
||||
TRY {
|
||||
//
|
||||
S sc=pipe.Open("QR")
|
||||
I $$$ISERR(sc) Q
|
||||
|
||||
// read queue/pipe and output to screen
|
||||
DO {
|
||||
K len S line=pipe.ReadLine(.len) I len=-1 Q
|
||||
S $LI(list,$I(pos))=line
|
||||
I echo W line,!
|
||||
} WHILE $G(pos)<1000
|
||||
|
||||
} CATCH {
|
||||
S ZE=$ZE
|
||||
BREAK
|
||||
}
|
||||
|
||||
// close pipe
|
||||
D pipe.Close()
|
||||
|
||||
// return list value
|
||||
Q list
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
Class Utils.Net [ Abstract ]
|
||||
{
|
||||
|
||||
ClassMethod QueryDNS(pHost As %String, Output ip As %List) As %Status
|
||||
{
|
||||
// some initialisation
|
||||
Set ip=$ListBuild()
|
||||
|
||||
// check host operating system and input parameters
|
||||
Set os=$Case($ZVersion(1), 1: "vms", 2: "win", 3: "*nx", : "")
|
||||
If (os="vms")||(os="") Quit $$$ERROR($$$GeneralError, "Not implemented.")
|
||||
If os="win" Set cmd="nslookup "_pHost
|
||||
If os="*nx" Set cmd="host "_pHost
|
||||
If $Match(pHost, "^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$")=0 {
|
||||
Quit $$$ERROR($$$GeneralError, "Invalid host name.")
|
||||
}
|
||||
|
||||
// enable end-of-file flagging
|
||||
Do $System.Process.SetZEOF(1)
|
||||
|
||||
// invoke command
|
||||
Open cmd:"QR":15
|
||||
If $Test {
|
||||
For i=1:1 {
|
||||
If i>100 Quit
|
||||
Use cmd Read row
|
||||
If $ZEOF Quit
|
||||
If os="win" Set os=$Select(row["Name:": "", 1: os) Continue
|
||||
Set ipv4=..GetIPAddr("ipv4", row)
|
||||
If $Length(ipv4) Set $List(ip, 4)=ipv4
|
||||
Set ipv6=..GetIPAddr("ipv6", row)
|
||||
If $Length(ipv6) Set $List(ip, 6)=ipv6
|
||||
}
|
||||
Close cmd
|
||||
}
|
||||
|
||||
// disable end-of-file flagging
|
||||
Do $System.Process.SetZEOF(0)
|
||||
|
||||
// finished
|
||||
If $ListData(ip, 4)=0, $ListData(ip, 6)=0 Quit $$$ERROR($$$GeneralError, "Lookup failed.")
|
||||
Quit $$$OK
|
||||
}
|
||||
|
||||
ClassMethod GetIPAddr(pType As %String = "", pRow As %String = "") As %String
|
||||
{
|
||||
If pType="ipv4" {
|
||||
Set pos=$Locate(pRow, "((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.|$)){4}")
|
||||
If pos Quit $Piece($Extract(pRow, pos, *), " ")
|
||||
} ElseIf pType="ipv6" {
|
||||
Set pos=$Locate(pRow, "([0-9A-Fa-f]{0,4}:){2,7}([0-9A-Fa-f]{1,4}$|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4})")
|
||||
If pos Quit $Piece($Extract(pRow, pos, *), " ")
|
||||
}
|
||||
Quit ""
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,7 +1,2 @@
|
|||
(iolib:lookup-hostname "www.kame.net" :ipv6 t)
|
||||
|
||||
#/IOLIB.SOCKETS:IP/203.178.141.194
|
||||
(#/IOLIB.SOCKETS:IP/2001:200:dff:fff1:216:3eff:feb1:44d7)
|
||||
"orange.kame.net"
|
||||
(("orange.kame.net" . #/IOLIB.SOCKETS:IP/203.178.141.194)
|
||||
("orange.kame.net" . #/IOLIB.SOCKETS:IP/2001:200:dff:fff1:216:3eff:feb1:44d7))
|
||||
(ipaddr-to-dotted (lookup-hostname "www.rosettacode.org"))
|
||||
"104.28.10.103"
|
||||
|
|
|
|||
2
Task/DNS-query/Common-Lisp/dns-query-4.lisp
Normal file
2
Task/DNS-query/Common-Lisp/dns-query-4.lisp
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(hostent-addr-list (resolve-host-ipaddr "www.rosettacode.org"))
|
||||
("104.28.11.103" "104.28.10.103")
|
||||
7
Task/DNS-query/Common-Lisp/dns-query-5.lisp
Normal file
7
Task/DNS-query/Common-Lisp/dns-query-5.lisp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
(iolib:lookup-hostname "www.kame.net" :ipv6 t)
|
||||
|
||||
#/IOLIB.SOCKETS:IP/203.178.141.194
|
||||
(#/IOLIB.SOCKETS:IP/2001:200:dff:fff1:216:3eff:feb1:44d7)
|
||||
"orange.kame.net"
|
||||
(("orange.kame.net" . #/IOLIB.SOCKETS:IP/203.178.141.194)
|
||||
("orange.kame.net" . #/IOLIB.SOCKETS:IP/2001:200:dff:fff1:216:3eff:feb1:44d7))
|
||||
3
Task/DNS-query/Common-Lisp/dns-query-6.lisp
Normal file
3
Task/DNS-query/Common-Lisp/dns-query-6.lisp
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(socket:ipaddr-to-dotted
|
||||
(socket:dns-query "www.rosettacode.org"))
|
||||
"104.28.10.103"
|
||||
7
Task/DNS-query/J/dns-query-1.j
Normal file
7
Task/DNS-query/J/dns-query-1.j
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
2!:0'dig -4 +short www.kame.net'
|
||||
orange.kame.net.
|
||||
203.178.141.194
|
||||
|
||||
2!:0'dig -6 +short www.kame.net'
|
||||
|interface error
|
||||
| 2!:0'dig -6 +short www.kame.net'
|
||||
21
Task/DNS-query/J/dns-query-2.j
Normal file
21
Task/DNS-query/J/dns-query-2.j
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import java.net.InetAddress;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
class DnsQuery {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
InetAddress[] ipAddr = InetAddress.getAllByName("www.kame.net");
|
||||
for(int i=0; i < ipAddr.length ; i++) {
|
||||
if (ipAddr[i] instanceof Inet4Address) {
|
||||
System.out.println("IPv4 : " + ipAddr[i].getHostAddress());
|
||||
} else if (ipAddr[i] instanceof Inet6Address) {
|
||||
System.out.println("IPv6 : " + ipAddr[i].getHostAddress());
|
||||
}
|
||||
}
|
||||
} catch (UnknownHostException uhe) {
|
||||
System.err.println("unknown host");
|
||||
}
|
||||
}
|
||||
}
|
||||
17
Task/DNS-query/REXX/dns-query-1.rexx
Normal file
17
Task/DNS-query/REXX/dns-query-1.rexx
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
/*REXX program displays IPv4 and IPv6 addresses for a supplied domain name.*/
|
||||
trace off /*don't show PING none─zero return code*/
|
||||
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.*/
|
||||
/*stick a fork in it, we're all done. */
|
||||
5
Task/DNS-query/REXX/dns-query-2.rexx
Normal file
5
Task/DNS-query/REXX/dns-query-2.rexx
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
irb(main):001:0> require 'socket'
|
||||
=> true
|
||||
irb(main):002:0> Addrinfo.getaddrinfo("www.kame.net", nil, nil, :DGRAM) \
|
||||
irb(main):003:0* .map! { |ai| ai.ip_address }
|
||||
=> ["203.178.141.194", "2001:200:dff:fff1:216:3eff:feb1:44d7"]
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
/*REXX pgm displays IPv4 and IPv6 addresses for a supplied domain name.*/
|
||||
trace off /*don't show the PING return code*/
|
||||
parse arg dn . /*get the optional domain name. */
|
||||
if dn=='' then dn = 'www.kame.net' /*Not specified? Then use default*/
|
||||
tmp = '\TEMP\TEMP.PING' /*define temp file to store IPv4.*/
|
||||
|
||||
do j=4 to 6 by 2 /*handle IPv4 and IPv6 addresses.*/
|
||||
'PING' (-j) '-l 0 -n 1' dn ">" tmp /*restrict PING's output to min. */
|
||||
q=charin(tmp,1,999) /*read output file from PING cmd.*/
|
||||
parse var q '[' IPA ']' /*parse IP a ddress from output.*/
|
||||
say 'IPv'j 'for domain name ' dn " is " IPA /*IPv4 | IPv6 addr.*/
|
||||
call lineout tmp /*needed by most REXXes to ··· */
|
||||
end /*j*/ /* [↑] ··· force file integrity.*/
|
||||
|
||||
'ERASE' tmp /*clean up the temporary file. */
|
||||
/*stick a fork in it, we're done.*/
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
import java.net.{InetAddress,Inet4Address,Inet6Address}
|
||||
import java.net.{Inet4Address, Inet6Address, InetAddress}
|
||||
|
||||
object DnsQuery extends App {
|
||||
val ipAddresses = InetAddress.getAllByName("www.kame.net");
|
||||
ipAddresses.foreach { ipAddr =>
|
||||
if (ipAddr.isInstanceOf[Inet4Address]) println("IPv4 : " + ipAddr.getHostAddress())
|
||||
else if (ipAddr.isInstanceOf[Inet6Address]) println("IPv6 : " + ipAddr.getHostAddress())
|
||||
InetAddress.getAllByName("google.com").foreach {
|
||||
case x: Inet4Address => println(s"IPv4 : ${x.getHostAddress}")
|
||||
case x: Inet6Address => println(s"IPv6 : ${x.getHostAddress}")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
16
Task/DNS-query/VBScript/dns-query.vb
Normal file
16
Task/DNS-query/VBScript/dns-query.vb
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
Function dns_query(url,ver)
|
||||
Set r = New RegExp
|
||||
r.Pattern = "Pinging.+?\[(.+?)\].+"
|
||||
Set objshell = CreateObject("WScript.Shell")
|
||||
Set objexec = objshell.Exec("%comspec% /c " & "ping -" & ver & " " & url)
|
||||
WScript.StdOut.WriteLine "URL: " & url
|
||||
Do Until objexec.StdOut.AtEndOfStream
|
||||
line = objexec.StdOut.ReadLine
|
||||
If r.Test(line) Then
|
||||
WScript.StdOut.WriteLine "IP Version " &_
|
||||
ver & ": " & r.Replace(line,"$1")
|
||||
End If
|
||||
Loop
|
||||
End Function
|
||||
|
||||
Call dns_query(WScript.Arguments(0),WScript.Arguments(1))
|
||||
Loading…
Add table
Add a link
Reference in a new issue