18
17

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.

はじめに

疎通確認でpingを使用する機会が度々あるが、
通信先がICPMプロトコルを許可していない場合、
特定ポートに対しての疎通確認を実施したい場合がある。

本記事では、MACやwindowsで使用できるポートを指定した疎通確認方法について記載する。

MAC編

nc(netcat)コマンド

コマンド

nc -vz {IPアドレスorドメイン} {ポート}

成功時

$ nc -vz google.com 80
Connection to google.com port 80 [tcp/http] succeeded!

失敗時

$ nc -vz google.com 81
nc: connectx to google.com port 81 (tcp) failed: Operation timed out

curlコマンド

コマンド

curl -I {IPアドレスorドメイン}:{ポート}

成功時

$ curl -I www.google.com:80
HTTP/1.1 200 OK
Content-Type: text/html; charset=ISO-8859-1
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Date: Sun, 03 Oct 2021 09:24:04 GMT
Server: gws
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Transfer-Encoding: chunked
Expires: Sun, 03 Oct 2021 09:24:04 GMT
Cache-Control: private
Set-Cookie: 1P_JAR=2021-10-03-09; expires=Tue, 02-Nov-2021 09:24:04 GMT; path=/; domain=.google.com; Secure
Set-Cookie: NID=511=ktOtFTcRbid0LdiusrRdSYnOTa3W63s-fcwZxp8mbHZYISVe9vmsX6f1cPeJJ6hC_nm5XA3_fXpURlFEl-utQcAv4javRXiAssgGUUO1AiacMwgGT1pu8dihyrygUXRC4fBtV59tm-8NwkUabqd4rjF6ua7YXWSqDDETDrWo-fg; expires=Mon, 04-Apr-2022 09:24:04 GMT; path=/; domain=.google.com; HttpOnly

失敗時

$ curl -I www.google.com:81
curl: (7) Failed to connect to www.google.com port 81: Operation timed out

Windows

Test-NetConnection (PowerShell)

コマンド

> Test-NetConnection {IPアドレスorドメイン} -Port {ポート}

成功時

> Test-NetConnection www.google.com -Port 80                                                                                                                                                                                                                                                                                                   ComputerName     : www.google.com
RemoteAddress    : 172.217.175.4
RemotePort       : 80
InterfaceAlias   : Wi-Fi
SourceAddress    : 10.229.71.193
TcpTestSucceeded : True

失敗時

> Test-NetConnection www.google.com -Port 81
警告: TCP connect to (172.217.175.4 : 81) failed

ComputerName           : www.google.com
RemoteAddress          : 172.217.175.4
RemotePort             : 81
InterfaceAlias         : Wi-Fi
SourceAddress          : 10.229.71.193
PingSucceeded          : True
PingReplyDetails (RTT) : 6 ms
TcpTestSucceeded       : False
18
17
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
18
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?