Help us understand the problem. What is going on with this article?

ncでお手軽tcpプロキシ

More than 3 years have passed since last update.

tl;dr

起動

# 8080に来たリクエストを192.168.59.103:8080に流す
# リクエスト保存先: outgoing.log
# レスポンス保存先: incoming.log
while :; do [[ -p fifo ]] || mkfifo fifo && nc -l 8080 < fifo | tee outgoing.log | nc 192.168.59.103 8080 | tee fifo > incoming.log; done
# ^Cで終了

ユースケース

Boot2Dockerでnginxを起動して手元のスマホからアクセス

# nginx起動してブラウザで確認
docker run -d --name nginx -p 8080:80 -v $DIR_PATH_DOCUMENT_ROOT:/usr/share/nginx/html:ro nginx

# プロキシ開始
while :; do [[ -p fifo ]] || mkfifo fifo && nc -l 8080 < fifo | tee outgoing.log | nc `boot2docker ip` 8080 | tee fifo > incoming.log; done

#### 別のシェルを開く
# ローカルホストでLISTENしていることを確認
netstat -anf inet | grep LISTEN | grep 8080

# ローカルホストのIPを確認
LOCAL_IP=`ifconfig en0 | grep "inet[^6]" | cut -d" " -f2`

# アクセス先アドレスを表示
echo http://$LOCAL_IP/

PCとスマホが同じLANに接続している必要があります。
PCのChromeで開けば、スマホのChromeの履歴から、PCで開いたアドレスを開くことが出来ます。

参考URL

http://notes.tweakblogs.net/blog/7955/using-netcat-to-build-a-simple-tcp-proxy-in-linux.html

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした