0
0

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 3 years have passed since last update.

Windowsから接続先へのTCPポート確認

Last updated at Posted at 2020-08-12

Linuxならtelnetでポート確認いけるのに、、、、

Windowsにもtelnet入れられますが、インストールが必要になります。
あまり環境に手を加えられないことはよくあるはず。
そんな時にWindowsでtelnet替わりに以下の手法でポート確認しました。

使い方

コマンドプロンプトにてpowershellを呼び出し

PS C:\> $tcp_chk = New-Object System.Net.Sockets.tcpClient
PS C:\> $tcp_chk.connect("10.0.0.10",8800)
PS C:\> $tcp_chk.connected

これで結果が

True

ならポートが開いていることがわかる

オブジェクトを閉じる

PS C:\> $tcp_chk.close()

ポートが開いてない場合は、以下のようなエラーとなるようです。

PS C:\> $tcp_chk = New-Object System.Net.Sockets.tcpClient
PS C:\> $tcp_chk.connect("10.0.0.10",8080)
"2" 個の引数を指定して "Connect" を呼び出し中に例外が発生しました: "接続済みの呼び出し先が一定の時間を過ぎても正しく応答しなかったため、接続できませんでした。または接続済みのホストが応答しなかったため、確立された接続は失敗しました。 10.0.0.10:8080"
発生場所 行:1 文字:1
+ $tcp_chk.connect("10.0.0.10",8080)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SocketException

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?