我正在使用我擁有的網域進行一些測試,我希望在執行 TXT 查詢時,接收 Base64 中的字串並對其進行解碼以顯示訊息。
在 Linux 上,它可以完美運作:
$ dig -t txt my.domain.com +short | sed -e 's/^"//' -e 's/"$//' | base64 -d > file.txt
$ cat file.txt
測試我的txt記錄
現在我想做同樣的事情,只不過在Windows中,預設情況下Windows沒有dig,但它有一個命令如下:
C:\Users\User\xyz>powershell Resolve-DnsName my.domain.com -Type
TXT > test
C:\Users\Avell\xyz>type test
Name Type TTL Section Strings
---- ---- --- ------- -------
my.domain.com TXT 10557 Answer
{dGVzdGluZyBvdXQgbXkgdHh0IHJlY29yZHMK}
我怎麼能讓上面的指令(Linux)適應Windows,只進行base64的攪拌和解碼來顯示訊息。
答案1
或者花必要的時間學習 PowerShell,利用 Youtube 上的所有免費資源和影片來了解 PowerShell 的所有部分,以及本機可以完成哪些操作以及何時需要自己編碼以及何時需要引入 3rdP 工具。
這不是第一次被問到這個問題。使用“PowerShell Sed”和“PowerShell Grep”進行快速網絡搜索,將向您展示這些甚至示例的良好列表。
Get-Content 取得指定位置處的項目內容。
Select-String 在字串和文件中尋找文字。
PowerShell 中的 sed
https://docs.microsoft.com/en-us/archive/blogs/sergey_babkins_blog/sed-in-powershell
PowerShell – UNIX SED 等效項 – 更改文件中的文本
https://www.kittell.net/code/powershell-unix-sed-equivalent-change-text-file
在 PowerShell 中使用 sed 和 grep
https://www.catapultsystems.com/blogs/using-sed-and-grep-in-powershell
http://www.systemcentercentral.com/using-sed-and-grep-in-powershell
Grep,PowerShell 方式
https://communary.net/2014/11/10/grep-the-powershell-way
如何在 PowerShell 中“grep”
https://antjanus.com/blog/web-development-tutorials/how-to-grep-in-powershell
如何在 PowerShell 中進行 Grep
https://www.adamfowlerit.com/2017/02/how-to-grep-in-powershell
快速提示:PowerShell Grep 等效項
https://dereknewton.com/2010/12/powershell-grep-equivalent
POWERSHELL:搜尋 POWERSHELL 的字串或 Grep
https://www.thomasmaurer.ch/2011/03/powershell-search-for-string-or-grep-for-powershell
其次,利用微軟 powershell 畫廊直接在您的 PowerShell 控制台或新的 Windows 終端機中...
Find-Module -Name '*grep*' | Format-Table -AutoSize
Version Name Repository Description
------- ---- ---------- -----------
1.1.0 PoshGrep PSGallery Greplike PowerShell function
Find-Package -Name '*grep*' | Format-Table -AutoSize
Name Version Source Summary
---- ------- ------ -------
wk.Grep 0.2.0 nuget.org Package Description
Liv.Grep 1.0.5436.17982 nuget.org Grep utility written in c#. Makes it easy to query command line outputs
AstroGrep 4.3.2 nuget.org This application and its source code are freely distributable.
GRepo 1.0.0 nuget.org GRepo
PoshGrep 1.1.0 PSGallery Greplike PowerShell function
....或使用 PowerShell 編輯器時 - 提供彈出式幫助/IntelliSense (PowerShell_ISE 內建,VScode下載,PowerShell 加號是免費的)或(Sapien 的 PowerShell 工作室- 需要花錢。
最後,您也在程式碼中使用 dig 。為此,請參閱: