Created
February 9, 2019 19:04
-
-
Save panakuma/bc6b5a38175691ee48836f5f7dba0078 to your computer and use it in GitHub Desktop.
PowerShellで名前解決して返すやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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