macOS と Linux の両方の場合:

macOS と Linux の両方の場合:

次のパイプラインを設定しました。これにより、パイプラインを通過する生の HTTP リクエストと応答を確認できます。

注記:私は以下の BSD を使用していますnc(これは macOS と AmazonLinux に付属しているものです) が、ncat同じ引数を取ることができる nmap の も試しました。socat1.7.3.2 の動作は同じです。は異なる引数を取りますが、パイプラインは同じです。説明は同じなので、ワンライナーのみ
socat追加します。socat

一発ギャグ:

mkfifo res; nc -kl 8888 < res | tee /dev/stderr | nc google.com 80 | tee res

または

mkfifo res; socat tcp-listen:8888,reuseaddr,fork - < res | tee /dev/stderr | socat - tcp:google.com:80 | tee res

説明:

mkfifo res; \             <-- Make a named pipe file with the name 'res'.
nc -kl 8888 < res \       <-- Open a socket listening on all interfaces at TCP port 8888. Use the 'res' pipe as input.
    | tee /dev/stderr \   <-- Copy the request to stderr, so it's emitted by the terminal. stdout will be used as input for the next netcat.
    | nc google.com 80 \  <-- Resolve google.com, connect to it on TCP port 80, and send what was received on stdin. The response goes to stdout.
    | tee res             <-- Copy the response to the 'res' pipe.

このパイプラインを1つのターミナル(パイプラインターミナル)を使用してcurl別の端末(カールターミナル):

curl --resolve google.com:8888:127.0.0.1 http://google.com:8888

macOS と Linux の両方の場合:

カールターミナル応答を正しく受信して表示します。パイプラインターミナルリクエストと応答を表示します。

macOS (macOS Mojave 10.14.3) の場合:

パイプラインは引き続き実行されます。 で別のリクエストを送信しcurl、そのリクエストをパイプラインターミナルそして、両方端末。

Linux (AmazonLinux 4.1.13) の場合:

パイプラインは実行を継続します。curl別のリクエストを送信するとハングし、リクエストや応答がどこにも表示されません。

バージョン:

マックOS

$ uname -a
Darwin ch007837.na.webmd.net 18.2.0 Darwin Kernel Version 18.2.0: Thu Dec 20 20:46:53 PST 2018; root:xnu-4903.241.1~1/RELEASE_X86_64 x86_64 i386 MacBookPro15,1 Darwin

$ curl --version
curl 7.64.1 (x86_64-apple-darwin18.2.0) libcurl/7.64.1 SecureTransport zlib/1.2.11
Release-Date: 2019-03-27
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile libz NTLM NTLM_WB SSL UnixSockets

$ bash --version | head -1
GNU bash, version 5.0.3(1)-release (x86_64-apple-darwin18.2.0)

$ ncat --version
Ncat: Version 7.70 ( https://nmap.org/ncat )

ncフラグがないのでよく分かりませんが--version、OS に付属していました。ただし、バイナリには次の文字列があります:

$ strings "$(which nc)" | tail -1
@(#)PROGRAM:nc  PROJECT:netcat-42.200.1

リナックス

$ uname -a
Linux ip-10-200-38-72 4.1.13-19.31.amzn1.x86_64 #1 SMP Wed Jan 20 00:25:47 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

$ curl --version
curl 7.40.0 (x86_64-redhat-linux-gnu) libcurl/7.40.0 NSS/3.19.1 Basic ECC zlib/1.2.8 libidn/1.18 libssh2/1.4.2
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz UnixSockets

$ bash --version | head -1
GNU bash, version 4.2.46(1)-release (x86_64-redhat-linux-gnu)

$ ncat --version
Ncat: Version 5.51 ( http://nmap.org/ncat )

$ yum list nc | tail -1 | sed 's/ \+/ /g'
nc.x86_64 1.84-24.8.amzn1 @amzn-main

関連情報