반응형
파워쉘로 도메인 정보를 확인할 수 있다.
프로필에 해당 함수를 등록하자.
프로필 확인 방법은 다음 포스팅을 참고하면 된다.
[IT/System Engineering] - 파워쉘 프로필 확인 및 설정
function Get-WhoIs {
[CmdletBinding()]
param(
# The query to send to WHOIS servers
[Parameter(Position=0, ValueFromRemainingArguments=$true)]
[string]$query,
# A specific whois server to search
[string]$server,
# Disable forwarding to new whois servers
[switch]$NoForward
)
end {
$TLDs = DATA {
@{
".br.com"="whois.centralnic.net"
".cn.com"="whois.centralnic.net"
".eu.org"="whois.eu.org"
".com"="whois.crsnic.net"
".net"="whois.crsnic.net"
".org"="whois.publicinterestregistry.net"
".edu"="whois.educause.net"
".gov"="whois.nic.gov"
}
}
$EAP, $ErrorActionPreference = $ErrorActionPreference, "Stop"
$query = $query.Trim()
if($query -match "(?:\d{1,3}\.){3}\d{1,3}") {
Write-Verbose "IP Lookup!"
if($query -notmatch " ") {
$query = "n $query"
}
if(!$server) { $server = "whois.arin.net" }
} elseif(!$server) {
$server = $TLDs.GetEnumerator() |
Where { $query -like ("*"+$_.name) } |
Select -Expand Value -First 1
}
if(!$server) { $server = "whois.arin.net" }
$maxRequery = 3
do {
Write-Verbose "Connecting to $server"
$client = New-Object System.Net.Sockets.TcpClient $server, 43
try {
$stream = $client.GetStream()
Write-Verbose "Sending Query: $query"
$data = [System.Text.Encoding]::Ascii.GetBytes( $query + "`r`n" )
$stream.Write($data, 0, $data.Length)
Write-Verbose "Reading Response:"
$reader = New-Object System.IO.StreamReader $stream, [System.Text.Encoding]::ASCII
$result = $reader.ReadToEnd()
if($result -match "(?s)Whois Server:\s*(\S+)\s*") {
Write-Warning "Recommended WHOIS server: ${server}"
if(!$NoForward) {
Write-verbose "Non-Authoritative Results:`n${result}"
# cache, in case we can't get an answer at the forwarder
if(!$cachedResult) {
$cachedResult = $result
$cachedServer = $server
}
$server = $matches[1]
$query = ($query -split " ")[-1]
$maxRequery--
} else { $maxRequery = 0 }
} else { $maxRequery = 0 }
} finally {
if($stream) {
$stream.Close()
$stream.Dispose()
}
}
} while ($maxRequery -gt 0)
$result
if($cachedResult -and ($result -split "`n").count -lt 5) {
Write-Warning "Original Result from ${cachedServer}:"
$cachedResult
}
$ErrorActionPreference = $EAP
}
}
# Set-Alias whois Get-WhoIs
사용법은 get-whois 도메인 이다.
반응형
'IT > System Engineering' 카테고리의 다른 글
[CentOS7] blockdev config 설정 (0) | 2021.04.14 |
---|---|
[CVE-2021-3156] sudo 취약점 패치 (0) | 2021.02.18 |
[PowerShell] 프로필 확인 및 설정 (0) | 2020.08.13 |
리눅스의 필수!! ps 명령어 총정리 (0) | 2020.08.01 |
Windows IIS TLS 1.0 TLS 1.1 비활성화 (0) | 2020.07.21 |
댓글