1. 程式人生 > >通過PowerShell獲取域名whois資訊

通過PowerShell獲取域名whois資訊

Whois 簡單來說,就是一個用來查詢域名是否已經被註冊,以及註冊域名的詳細資訊的資料庫(如域名所有人、域名註冊商、域名註冊日期和過期日期等)。通過域名Whois伺服器查詢,可以查詢域名歸屬者聯絡方式,以及註冊和到期時間。通常情況下,whois資訊均為真實資訊,通過whois資訊可以找到域名註冊人的很多真實資訊,像電話,郵箱,NS記錄,是對網站進行社工非常好的資訊來源,對於安全從業人員來說,快速獲取whois資訊,能夠幫助自己掌握目標網站的很多有用資訊。

而whois資訊通常是儲存在各級域名註冊機構中,平常我們要查詢whois資訊都是通過godaddy、name.com、萬網、新網等域名註冊商網站通過查詢頁面提交域名進行查詢,既慢又不能批量查詢,太費勁了,這裡我就把我珍藏很久的一個PS function貢獻給大家,這個指令碼支援140多種字尾的域名進行查詢,尤其是一些生僻的域,找一個能支援這個域註冊的註冊商就不容易了,現在你不需要再為這個事情發愁了。

老規矩,先上程式碼,然後對關鍵操作進行解釋:

        =====檔名:Get-whois.ps1=====
 function Get-WhoIs {
<# Author:fuhj(powershell#live.cn ,http://fuhaijun.com)  
    # Does a raw WHOIS query and returns the results
    #   The simplest whois search
    #.Example
    #   get-whois dnspod.com
    #
    #   This example is one that forwards to a second whois server ...
#.Example # get-whois baidu.com -NoForward # # Returns the partial results you get when you don't follow forwarding to a new whois server # get-whois n 128.11.5.98 -server whois.arin.net # # Does an ip lookup at arin.net #> [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 { @{ ".com"= "whois.verisign-grs.com","whois.crsnic.net" ".net"= "whois.verisign-grs.com","whois.crsnic.net" ".org"= "whois.pir.org","whois.publicinterestregistry.net" ".info"= "whois.afilias.info","whois.afilias.net" ".biz"= "whois.neulevel.biz" ".us"= "whois.nic.us" ".uk"= "whois.nic.uk" ".ca"= "whois.cira.ca" ".tel"= "whois.nic.tel" ".ie"= "whois.iedr.ie","whois.domainregistry.ie" ".it"= "whois.nic.it" ".li"= "whois.nic.li" ".no"= "whois.norid.no" ".cc"= "whois.nic.cc" ".eu"= "whois.eu" ".nu"= "whois.nic.nu" ".au"= "whois.aunic.net","whois.ausregistry.net.au" ".de"= "whois.denic.de" ".ws"= "whois.worldsite.ws","whois.nic.ws","www.nic.ws" ".sc"= "whois2.afilias-grs.net" ".mobi" = "whois.dotmobiregistry.net" ".pro"= "whois.registrypro.pro","whois.registry.pro" ".edu"= "whois.educause.net","whois.crsnic.net" ".tv"= "whois.nic.tv","tvwhois.verisign-grs.com" ".travel" = "whois.nic.travel" ".name" = "whois.nic.name" ".in"= "whois.inregistry.net","whois.registry.in" ".me"= "whois.nic.me","whois.meregistry.net" ".at"= "whois.nic.at" ".be"= "whois.dns.be" ".cn"= "whois.cnnic.cn","whois.cnnic.net.cn" ".edu.cn"="whois.edu.cn" ".asia"= "whois.nic.asia" ".ru"= "whois.ripn.ru","whois.ripn.net" ".ro"= "whois.rotld.ro" ".aero" = "whois.aero" ".fr"= "whois.nic.fr" ".se"= "whois.iis.se","whois.nic-se.se","whois.nic.se" ".nl"= "whois.sidn.nl","whois.domain-registry.nl" ".nz"= "whois.srs.net.nz","whois.domainz.net.nz" ".mx"= "whois.nic.mx" ".tw"= "whois.apnic.net","whois.twnic.net.tw" ".ch"= "whois.nic.ch" ".hk"= "whois.hknic.net.hk" ".ac"= "whois.nic.ac" ".ae"= "whois.nic.ae" ".af"= "whois.nic.af" ".ag"= "whois.nic.ag" ".al"= "whois.ripe.net" ".am"= "whois.amnic.net" ".as"= "whois.nic.as" ".az"= "whois.ripe.net" ".ba"= "whois.ripe.net" ".bg"= "whois.register.bg" ".bi"= "whois.nic.bi" ".bj"= "www.nic.bj" ".br"= "whois.nic.br" ".br.com"="whois.centralnic.net" ".eu.org"="whois.eu.org" ".bt"= "whois.netnames.net" ".by"= "whois.ripe.net" ".bz"= "whois.belizenic.bz" ".cd"= "whois.nic.cd" ".ck"= "whois.nic.ck" ".cl"= "nic.cl" ".coop"= "whois.nic.coop" ".cx"= "whois.nic.cx" ".cy"= "whois.ripe.net" ".cz"= "whois.nic.cz" ".dk"= "whois.dk-hostmaster.dk" ".dm"= "whois.nic.cx" ".dz"= "whois.ripe.net" ".ee"= "whois.eenet.ee" ".eg"= "whois.ripe.net" ".es"= "whois.ripe.net" ".fi"= "whois.ficora.fi" ".fo"= "whois.ripe.net" ".gb"= "whois.ripe.net" ".ge"= "whois.ripe.net" ".gl"= "whois.ripe.net" ".gm"= "whois.ripe.net" ".gov"= "whois.nic.gov" ".gr"= "whois.ripe.net" ".gs"= "whois.adamsnames.tc" ".hm"= "whois.registry.hm" ".hn"= "whois2.afilias-grs.net" ".hr"= "whois.ripe.net" ".hu"= "whois.ripe.net" ".il"= "whois.isoc.org.il" ".int"= "whois.isi.edu" ".iq"= "vrx.net" ".ir"= "whois.nic.ir" ".is"= "whois.isnic.is" ".je"= "whois.je" ".jp"= "whois.jprs.jp" ".kg"= "whois.domain.kg" ".kr"= "whois.nic.or.kr" ".la"= "whois2.afilias-grs.net" ".lt"= "whois.domreg.lt" ".lu"= "whois.restena.lu" ".lv"= "whois.nic.lv" ".ly"= "whois.lydomains.com" ".ma"= "whois.iam.net.ma" ".mc"= "whois.ripe.net" ".md"= "whois.nic.md" ".mil"= "whois.nic.mil" ".mk"= "whois.ripe.net" ".ms"= "whois.nic.ms" ".mt"= "whois.ripe.net" ".mu"= "whois.nic.mu" ".my"= "whois.mynic.net.my" ".nf"= "whois.nic.cx" ".pl"= "whois.dns.pl" ".pr"= "whois.nic.pr" ".pt"= "whois.dns.pt" ".sa"= "saudinic.net.sa" ".sb"= "whois.nic.net.sb" ".sg"= "whois.nic.net.sg" ".sh"= "whois.nic.sh" ".si"= "whois.arnes.si" ".sk"= "whois.sk-nic.sk" ".sm"= "whois.ripe.net" ".st"= "whois.nic.st" ".su"= "whois.ripn.net" ".tc"= "whois.adamsnames.tc" ".tf"= "whois.nic.tf" ".th"= "whois.thnic.net" ".tj"= "whois.nic.tj" ".tk"= "whois.nic.tk" ".tl"= "whois.domains.tl" ".tm"= "whois.nic.tm" ".tn"= "whois.ripe.net" ".to"= "whois.tonic.to" ".tp"= "whois.domains.tl" ".tr"= "whois.nic.tr" ".ua"= "whois.ripe.net" ".uy"= "nic.uy" ".uz"= "whois.cctld.uz" ".va"= "whois.ripe.net" ".vc"= "whois2.afilias-grs.net" ".ve"= "whois.nic.ve" ".vg"= "whois.adamsnames.tc" ".yu"= "whois.ripe.net" } } $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 | Get-Random } 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 } }

函式裡定義了三個引數,兩個[string]型別,一個[switch]型別,分別用於接收要進行whois查詢的域名,指定whois域名伺服器,以及是否允許將查詢請求轉發到其他域名解析伺服器。隨後建立了一個列舉值的雜湊表,目的是用於儲存不同域名字尾和whois伺服器的對應關係,因為不同的域名字尾對應的域名資訊是儲存在不同的伺服器上的。需要強調的是像.com、.net、.org、.info這幾個註冊量特別大的域名字尾指定了多個whois伺服器,避免查詢量過大無法有效返回結果的問題。

接下來通過New-Object建立一個System.Net.Sockets.TcpClient的TCP物件,連線上面指定的whois伺服器的43埠用於查詢whois資訊,在通過一個System.IO.StreamReader物件接收whois資訊返回的資料,並對資料進行解析。除此之外再加上try{}cache{}finally{}進行容錯處理,在資料解析是也用到了正則表示式用於匹配目標字串。

程式的執行方法有如下四種:

get-whois dnspod.com

先看看dnspod在被騰訊收購後有沒有更改whois資訊,貌似鵝廠沒有改過

image
get-whois jd.com –NoForward

image
get-whois n 128.11.5.98 -server whois.arin.net

 image

作者: 付海軍
出處:http://fuhj02.cnblogs.com
版權:本文版權歸作者和部落格園共有
轉載:歡迎轉載,為了儲存作者的創作熱情,請按要求【轉載】,謝謝
要求:未經作者同意,必須保留此段宣告;必須在文章中給出原文連線;否則必究法律責任
個人網站: http://www.fuhaijun.com/

相關推薦

通過PowerShell獲取域名whois資訊

Whois 簡單來說,就是一個用來查詢域名是否已經被註冊,以及註冊域名的詳細資訊的資料庫(如域名所有人、域名註冊商、域名註冊日期和過期日期等)。通過域名Whois伺服器查詢,可以查詢域名歸屬者聯絡方式,以及註冊和到期時間。通常情況下,whois資訊均為真實資訊,通過whois資訊可以找到域名註冊人的很多真實資

騰訊地圖逆地址解析,通過經緯度獲取詳細的資訊資料

根據騰訊地圖API,以圖文的方式一步一步的來說明如何獲取詳細的位置資訊資料。具體參考騰訊地圖Webservice API的簡介。騰訊地圖WebService API   第一步:申請開發者金鑰(key)申請金鑰       我選擇的應用型別為瀏覽器型別(呼叫Javascr

VUE:vue通過cookie獲取使用者登入資訊

思路 進入頁面 若未登入,跳轉至登陸頁面 若已登入,從cookie中獲取使用者資訊,並執行後續操作 1. 登入頁面,存入cookie(setCookie) import {setCookie,getCookie}from 'src/js/cookieUtil

深入挖掘protobuf: 通過protoc獲取proto檔案資訊

準備: 預備知識: 已經使用過protobuf, 熟練應用protobuf序列化在各語言間互動資訊 目標: 獲取proto內容而無需手動解析proto檔案 為proto檔案新增更多的meta資訊, 並在執行期獲取. protoc編譯器準備 通過protobuf-2.5的原始碼或者從官網下載, 可以

PHP實現通過geoip獲取IP地理資訊

如果想獲取到使用者的地理資訊可以通過geoip來實現,或者第三方介面,下面是geoip庫的實現方式 geoip是通過來訪者的IP,定位他的經緯度,國家/地區,省市,甚至街道等位置資訊 torann/geoip 是為 Laravel 定製的獲取 IP 地理資訊的擴充套件包 1

通過PowerShell獲取TCP響應(類Telnet)

通常情況下,為了檢測指定的TCP埠是否存活,我們都是通過telnet指定的埠看是否有響應來確定,然而預設情況下win8以後的系統預設是不安裝telnet的。設想一下如果你黑進了一個伺服器,上面沒裝telnet,但是為了進一步滲透進內網,需要探測內部伺服器特定埠是否開啟,同時你還不願意安裝telnet,擔心引起

java中通過request獲取客戶端資訊

轉自:孤傲蒼狼     getRequestURL方法返回客戶端發出請求時的完整URL。   getRequestURI方法返回請求行中的資源名部分。  getQueryString 方法返回請求行中的引數部分。  getPathInfo方法返回請求URL中的額外路徑資訊

利用JNI方法,通過WMI獲取本地硬體資訊(主機板型號,硬碟序列號,CPU引數等)

因為有幾臺伺服器是windows 2000的,之前採用的WMIC方法不適用(windows 2003開始有),更不用說WMI .NET了(採用.NET Framework 3.5),只能採用JNI的方法,通過C++來呼叫本地WMI介面來查詢資料。幸好,這次WMI從windo

通過經緯度獲取地理位置資訊

最近做一個車載裝置app,裝置獲取北斗gps資料上傳的到後臺,app通過後臺提供的經緯度反取地理編碼位置,支援Google和百度。 獲取地理位置url //Google public Strin

通過request獲取網頁資訊 通過BeautifulSoup剖析網頁元素

獲取網頁 alink his odi res req 特定 bsp css屬性 import requests newsUrl =‘http://news.sina.com.cn/china/‘ res = requests.get(newsUrl) res.encod

通過adb shell獲取當前視窗資訊

通過adb shell獲取當前視窗,目的是判斷是否有電話接入 獲取當前視窗資訊: adb shell dumpsys window windows | grep mCurrent  在鎖屏狀態:mCurrentFocus=Window{d4d7e33 u0 com.ss.and

通過關鍵字獲取漏洞平臺最新漏洞資訊

因要每天去查詢漏洞資訊,來判斷架構和應用服務有沒有新漏洞被發現,若有 則需修復升級。所以寫了一個去漏洞庫平臺通過關鍵字爬取資料生成日誌檔案,這三個平臺,就美國國家資訊保安漏洞庫地址會時不時出現超時情況。若出現超時,可多試兩次,三個平臺檢索出的漏洞差不多,寫的不好,僅供參考 python版本3.7pip安裝r

前端Vue框架(通過axios獲取地址串(介面)資訊)

獲取地址串資訊:某些公司會提供一些地址串的介面,可以通過vue框架使用axios獲取裡面的值,並迴圈遍歷參考程式碼:   <!DOCTYPE html> <html> <head> <title>demo5 社群作業1</

精益資料分析讀書筆記——第四章-以資料為嚮導與通過資料獲取資訊

這章沒太看懂……以後回頭再看 濫用資料容易導致區域性優化,進而忽視大局,這是極其危險乃至致命的。 人類提供靈感,機器負責驗證 數學在優化已知系統方向可以做的很好,而人類更善於發現新的系統。換言之,漸進式的改變可以達到區域性極限,創新則可能導致全域性洗牌。 #資料

C#通過shell32獲取檔案詳細備註資訊

1.從系統Window/System32資料夾中Copy出 Shell32.dll Com元件 將Shell32.dll檔案引用到專案中,並設定“嵌入互操作型別”為false 2.程式碼例項: ShellClass sh = new ShellClass(); Fold

使用PowerShell 獲取azure image publisher offer sku 資訊

使用azure powershell 獲取指定區域的可用映象 publisher offer sku資訊    param ( [parameter(Mandatory = $false)] $LocationName = "ChinaNorth", [p

C++ 通過登錄檔獲取Windows版本資訊

原理:通過訪問登錄檔 HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion 下的鍵值資訊來獲取windows版本資訊。由於是訪問登錄檔獲取的資訊,所以準確性一般。 #include <

學習淘淘商城第八十九課(單點登入之通過token獲取使用者資訊

        首先還是看介面文件關於通過token獲取使用者資訊的說明,如下圖所示。             看了說明文件我們便知道該怎麼做了,在taotao-sso-interface工程的UserService介面類中新增一個介面,如下圖所示。          

Android-通過網路獲取xml檔案使用pull解析得到伺服器中的資訊(新聞客戶端)

通過網路獲取xml檔案,使用pull解析該檔案得到伺服器中的資訊; demo中使用了一個開源的圖片載入包,故上傳原始碼方便檢視; 效果圖: 步驟: 1.連線伺服器獲取xml檔案; 2.使用pull解析xml檔案存入實體物件中; 3.解析後將實體物件存入List集合中;

IIS7.5部署站點後獲取檔案物理路徑及web虛擬路徑、以及獲取通過Request.Uri獲取部署地址資訊

1、在部署到IIS後,我們儲存檔案需要獲取實際實體地址及web虛擬地址,可以通過以下方式獲取: 通過Hosting.HostingEnviroment獲取實體地址和虛擬地址 var appPhysicalPath = System.Web.Hosting.HostingEnvironment.A