2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Windows 10 PCからの疎通確認実行方法

Last updated at Posted at 2020-02-25

はじめに

Windows10のPCでWSL(Windows Subsystem for Linux)環境を手に入れてからはWindowsのコマンドを使うことから遠ざかっていたが、最近自分のPC以外で作業することも多く、そう都合よくWSLのUbuntu等が完備されていることは少ない。特に複数人が使う作業用端末には間違いなく導入されていない。
そういう場合、デフォルトで常備されているツールを使うことになるが、Windows PowerShellであればWindowsデフォルトで導入されているため、お手軽に利用できる。

今回はネットワーク疎通確認のための Test-NetConnection コマンドの使用例を記載する。

Test-NetConnectionコマンド

Test-NetConnection コマンドはネットワークの疎通確認用のコマンドで、以下オプションが利用可能。

パラメーター
    -CommonTCPPort <string>
    -ComputerName <string>
    -ConstrainInterface <uint32>
    -ConstrainSourceAddress <string>
    -DiagnoseRouting
    -Hops <int>
    -TraceRoute

  -Port  <-- Get-Helpでは表示されなかった

疎通確認にはポートを指定することが多いので、Test-NetConnection xxx -Port XXのような使い方になる。

疎通確認実行例

実際にgoogle.comに対して実行してみた例を記載する。

> Test-NetConnection google.com -Port 80

ComputerName     : google.com
RemoteAddress    : 2404:6800:4004:81e::200e
RemotePort       : 80
InterfaceAlias   : イーサネット 3
SourceAddress    : xxx
TcpTestSucceeded : True

ポートが開放されていない場合は以下のように表示され、結果はFalseとなる。

> Test-NetConnection google.com -Port 123
警告: TCP connect to (2404:6800:4004:81e::200e : 123) failed
警告: TCP connect to (172.217.175.78 : 123) failed

ComputerName           : google.com
RemoteAddress          : 2404:6800:4004:81e::200e
RemotePort             : 123
InterfaceAlias         : イーサネット 3
SourceAddress          : xxx
PingSucceeded          : True
PingReplyDetails (RTT) : 50 ms
TcpTestSucceeded       : False


ちなみに、Ubuntuからcurlでポート指定の疎通確認を実行した場合の表示はこちら。

$ curl -v telnet://www.google.com:80
* Rebuilt URL to: telnet://www.google.com:80/
*   Trying 2404:6800:4004:818::2004...
* Connected to www.google.com (2404:6800:4004:818::2004) port 80 (#0)

$
$ curl -v telnet://google.com:123
* Rebuilt URL to: telnet://google.com:123/
*   Trying 2404:6800:4004:81c::200e...
*   Trying 172.217.175.14...
* connect to 2404:6800:4004:81c::200e port 123 failed: Connection refused
* connect to 172.217.175.14 port 123 failed: Connection refused
* Failed to connect to google.com port 123: Connection refused
* Closing connection 0
curl: (7) Failed to connect to google.com port 123: Connection refused

curlで実行した場合はすぐに結果が表示されるが、TestNetConnectionコマンドを実行した場合は結果が表示されるまで少し遅く感じた。ポート開放していない場合はタイムアウトを待つため数十秒待った。

まとめ

いざというときにWindows PowerShellが役に立つ。

(追記)Windows 7 SP1(詳細バージョン不明)にはこのコマンドは含まれていない模様。

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?