Skip to content

Instantly share code, notes, and snippets.

@panakuma
Created February 9, 2019 19:04
Show Gist options
  • Save panakuma/bc6b5a38175691ee48836f5f7dba0078 to your computer and use it in GitHub Desktop.
Save panakuma/bc6b5a38175691ee48836f5f7dba0078 to your computer and use it in GitHub Desktop.
PowerShellで名前解決して返すやつ
function Dns-Resolver([String]$domain, [int]$type) {
Add-Type -AssemblyName System.Net
[array]$HostEntries = [System.Net.DNS]::GetHostEntry($domain)
switch($type){
4 {
[array]$IPaddresses = $HostEntries.AddressList | ?{$_.AddressFamily -eq "InterNetwork"}
}
6 {
[array]$IPaddresses = $HostEntries.AddressList | ?{$_.AddressFamily -eq "InterNetworkV6"}
}
}
return ($IPaddresses[0]).IPAddressToString
}
# 使い方
# Dns-Resolver ドメイン名 IPアドレスバージョン
# Dns-Resolver gist.github.com 4 ← GithubGistのIPv4アドレスが返ってくる
# Dns-Resolver www.google.co.jp 6 ← GoogleのIPv6アドレスが返ってくる
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment