Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
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 ""
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue