PowerShell/指定したポートのTCPが開放されているか調べる方法・Test-NetConnection
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#navi(../)
* PowerShellで指定したポートのTCPが開放されているか調べる...
サーバに対して、ポートが開いているどうかの確認のため、Win...
telnetコマンドにポート番号とサーバを指定しポートが開放さ...
PowerShellでは、Test-NetConnectionコマンドレットを使用す...
以下にいくつかの実行例を記します。
#contents
#htmlinsertpcsp(win-top.html,win-sp.html)
* 関連記事 [#cfd4bc92]
-[[PowerShellでpingをする方法>PowerShell/pingができるコマ...
-[[指定したポートのTCPが開放されているか調べる方法・Test-...
* man Test-NetConnection [#j20645ee]
Test-NetConnectionコマンドレットの使用方法です。
PS C:\> man Test-NetConnection
名前
Test-NetConnection
構文
Test-NetConnection [[-ComputerName] <string>] [<Com...
Test-NetConnection [[-ComputerName] <string>] [-Comm...
Test-NetConnection [[-ComputerName] <string>] [<Com...
Test-NetConnection [[-ComputerName] <string>] [<Com...
エイリアス
TNC
注釈
Get-Help を実行しましたが、このコンピューターにこの...
-- このコマンドレットを含むモジュールのヘルプ フ...
* ポート番号を指定して確認 [#ued137e9]
以下のようにポート番号を指定してHTTPの80ポートが開放され...
オプション-Portでポート番号を指定します。
Test-NetConnection -ComputerName win.just4fun.biz -Port 80
#ref(01.png)
#br
#ref(02.png)
&color(red){上記のスクリーンショットをみると、Waiting for...
&color(red){これを''非表示''にする場合は、以下のようにし...
* Waiting for response メッセージを非表示にする [#d14e7909]
非表示にするには、$ProgressPreferenceに''SilentlyContinue...
変更前は以下のように Continue が設定されています。
PS C:\> $ProgressPreference
Continue
非表示にするには、以下のように変更します。
PS C:\> $ProgressPreference = "SilentlyContinue"
この設定後、Test-NetConnectionコマンドを実施してください。~
Waitng for responseのメッセージは表示されなくなります。
* プロトコルを指定して確認 [#lec5ad05]
オプションの-CommonTCPPortにプロトコル名を指定して実行し...
** HTTPプロトコルと指定した場合 [#ofd0b36f]
PS C:\> Test-NetConnection -ComputerName win.just4fun.bi...
ComputerName : win.just4fun.biz
RemoteAddress : 157.7.107.123
RemotePort : 80
InterfaceAlias : Wi-Fi
SourceAddress : 192.168.1.24
TcpTestSucceeded : True
** SMBプロトコルと指定した場合 [#ce9ef4df]
PS C:\> Test-NetConnection -ComputerName pi.local -Commo...
ComputerName : pi.local
RemoteAddress : 192.168.1.81
RemotePort : 445
InterfaceAlias : Wi-Fi
SourceAddress : 192.168.1.24
TcpTestSucceeded : True
* エラーの場合 [#n28bfa0c]
ポート開放されていない場合の出力になります。~
TcpTestSucceededがFalseになっているのが確認できます。
-サーバが存在しない
PS C:\> Test-NetConnection -ComputerName foo -Port 123
警告: Name resolution of foo failed
ComputerName : foo
RemoteAddress :
InterfaceAlias :
SourceAddress :
PingSucceeded : False
-ポート開放されていない場合
PS C:\> $result = Test-NetConnection -ComputerName pi.lo...
警告: TCP connect to (192.168.1.81 : 123) failed
PS C:\> $result
ComputerName : pi.local
RemoteAddress : 192.168.1.81
RemotePort : 123
InterfaceAlias : Wi-Fi
SourceAddress : 192.168.1.24
PingSucceeded : True
PingReplyDetails (RTT) : 1 ms
TcpTestSucceeded : False
PS C:\> $result.TcpTestSucceeded
False
* True/Falseのみ返却してほしい場合 [#cda81382]
ポート開放されているかどうかの戻り値としてTrueまたはFalse...
PS C:\> Test-NetConnection -ComputerName pi.local -Port ...
True
PS C:\> Test-NetConnection -ComputerName pi.local -Port ...
警告: TCP connect to (192.168.1.81 : 23) failed
False
以上、PowerShellのTest-NetConnectionコマンドレットを使用...
#htmlinsertpcsp(win-btm.html,win-sp.html)
終了行:
#navi(../)
* PowerShellで指定したポートのTCPが開放されているか調べる...
サーバに対して、ポートが開いているどうかの確認のため、Win...
telnetコマンドにポート番号とサーバを指定しポートが開放さ...
PowerShellでは、Test-NetConnectionコマンドレットを使用す...
以下にいくつかの実行例を記します。
#contents
#htmlinsertpcsp(win-top.html,win-sp.html)
* 関連記事 [#cfd4bc92]
-[[PowerShellでpingをする方法>PowerShell/pingができるコマ...
-[[指定したポートのTCPが開放されているか調べる方法・Test-...
* man Test-NetConnection [#j20645ee]
Test-NetConnectionコマンドレットの使用方法です。
PS C:\> man Test-NetConnection
名前
Test-NetConnection
構文
Test-NetConnection [[-ComputerName] <string>] [<Com...
Test-NetConnection [[-ComputerName] <string>] [-Comm...
Test-NetConnection [[-ComputerName] <string>] [<Com...
Test-NetConnection [[-ComputerName] <string>] [<Com...
エイリアス
TNC
注釈
Get-Help を実行しましたが、このコンピューターにこの...
-- このコマンドレットを含むモジュールのヘルプ フ...
* ポート番号を指定して確認 [#ued137e9]
以下のようにポート番号を指定してHTTPの80ポートが開放され...
オプション-Portでポート番号を指定します。
Test-NetConnection -ComputerName win.just4fun.biz -Port 80
#ref(01.png)
#br
#ref(02.png)
&color(red){上記のスクリーンショットをみると、Waiting for...
&color(red){これを''非表示''にする場合は、以下のようにし...
* Waiting for response メッセージを非表示にする [#d14e7909]
非表示にするには、$ProgressPreferenceに''SilentlyContinue...
変更前は以下のように Continue が設定されています。
PS C:\> $ProgressPreference
Continue
非表示にするには、以下のように変更します。
PS C:\> $ProgressPreference = "SilentlyContinue"
この設定後、Test-NetConnectionコマンドを実施してください。~
Waitng for responseのメッセージは表示されなくなります。
* プロトコルを指定して確認 [#lec5ad05]
オプションの-CommonTCPPortにプロトコル名を指定して実行し...
** HTTPプロトコルと指定した場合 [#ofd0b36f]
PS C:\> Test-NetConnection -ComputerName win.just4fun.bi...
ComputerName : win.just4fun.biz
RemoteAddress : 157.7.107.123
RemotePort : 80
InterfaceAlias : Wi-Fi
SourceAddress : 192.168.1.24
TcpTestSucceeded : True
** SMBプロトコルと指定した場合 [#ce9ef4df]
PS C:\> Test-NetConnection -ComputerName pi.local -Commo...
ComputerName : pi.local
RemoteAddress : 192.168.1.81
RemotePort : 445
InterfaceAlias : Wi-Fi
SourceAddress : 192.168.1.24
TcpTestSucceeded : True
* エラーの場合 [#n28bfa0c]
ポート開放されていない場合の出力になります。~
TcpTestSucceededがFalseになっているのが確認できます。
-サーバが存在しない
PS C:\> Test-NetConnection -ComputerName foo -Port 123
警告: Name resolution of foo failed
ComputerName : foo
RemoteAddress :
InterfaceAlias :
SourceAddress :
PingSucceeded : False
-ポート開放されていない場合
PS C:\> $result = Test-NetConnection -ComputerName pi.lo...
警告: TCP connect to (192.168.1.81 : 123) failed
PS C:\> $result
ComputerName : pi.local
RemoteAddress : 192.168.1.81
RemotePort : 123
InterfaceAlias : Wi-Fi
SourceAddress : 192.168.1.24
PingSucceeded : True
PingReplyDetails (RTT) : 1 ms
TcpTestSucceeded : False
PS C:\> $result.TcpTestSucceeded
False
* True/Falseのみ返却してほしい場合 [#cda81382]
ポート開放されているかどうかの戻り値としてTrueまたはFalse...
PS C:\> Test-NetConnection -ComputerName pi.local -Port ...
True
PS C:\> Test-NetConnection -ComputerName pi.local -Port ...
警告: TCP connect to (192.168.1.81 : 23) failed
False
以上、PowerShellのTest-NetConnectionコマンドレットを使用...
#htmlinsertpcsp(win-btm.html,win-sp.html)
ページ名: