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

bash で TCP 通信

More than 5 years have passed since last update.

使い道あるかわからないけれど、/dev/tcp/{hostname}/{port} で TCP 通信できる。(※ただし bash に限る?)

http_client.sh
#!/bin/bash
# 使い方
#  $ ./http_client.sh host path
# http://host/path に GET 投げる

exec 3<> /dev/tcp/$1/80
echo -e "GET $2 HTTP/1.0\n\n" >&3
cat <&3

実行してみる。

$ ./http_client.sh qiita.com /
HTTP/1.1 200 OK
Server: nginx/1.0.9
Date: Wed, 22 Feb 2012 01:19:59 GMT
Content-Type: text/html
Content-Length: 151
Last-Modified: Tue, 01 Nov 2011 15:07:17 GMT
Connection: close
Accept-Ranges: bytes

<html>
<head>
<title>Welcome to nginx!</title>
</head>
<body bgcolor="white" text="black">
<center><h1>Welcome to nginx!</h1></center>
</body>
</html>
$ 

ちなみに /dev/udp/{hostname}/{port} で UDP 通信。

k_ui
ねこほしい
http://k-ui.jp
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
ユーザーは見つかりませんでした