因此,我必须从http://www.rssweather.com/dir/Asia/India检索任何一个城市的温度.
我们假设我要检索坎普尔的.
如何使用Netcat发出HTTP GET请求?
我正在做这样的事情.
nc -v rssweather.com 80
GET http://www.rssweather.com/wx/in/kanpur/wx.php HTTP/1.1
Run Code Online (Sandbox Code Playgroud)
我不确切地知道我是否在正确的方向.我无法找到关于如何使用netcat发出HTTP get请求的任何好教程,所以我在这里发布它.
pet*_*ica 26
Of course you could dig in standards searched for google, but actually if you want to get only a single URL, it doesn't worth the effort.
You could also start a netcat in listening mode on a port:
nc -l 64738
Run Code Online (Sandbox Code Playgroud)
...然后使用真实浏览器向此端口发出浏览器请求.只需输入您的浏览器即可http://localhost:64738.
在您的实际情况中,问题是HTTP/1.1不会自动关闭连接,但它会等待您要检索的下一个URL.解决方案很简单:
使用HTTP/1.0:
GET /this/url/you/want/to/get HTTP/1.0
Host: www.rssweather.com
<empty line>
Run Code Online (Sandbox Code Playgroud)
或者使用Connection:请求标头说出之后要关闭的服务器:
GET /this/url/you/want/to/get HTTP/1.1
Host: www.rssweather.com
Connection: close
<empty line>
Run Code Online (Sandbox Code Playgroud)
扩展:在GET头之后只写入请求的路径部分.您要从中获取数据的主机名属于Host:标题,您可以在我的示例中看到.这是因为多个网站可以在同一个网络服务器上运行,因此浏览器需要说出他们想从哪个服务器加载页面.
Gra*_*ett 12
在 MacOS 上,您需要 -c 标志,如下所示:
Little-Net:~ minfrin$ nc -c rssweather.com 80
GET /wx/in/kanpur/wx.php HTTP/1.1
Host: rssweather.com
Connection: close
[empty line]
Run Code Online (Sandbox Code Playgroud)
然后响应如下所示:
HTTP/1.1 200 OK
Date: Thu, 23 Aug 2018 13:20:49 GMT
Server: Apache
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html
Run Code Online (Sandbox Code Playgroud)
-c 标志被描述为“发送 CRLF 作为行尾”。
要与 HTTP/1.1 兼容,您需要 Host 标头,如果要禁用 keepalive,还需要“Connection: close”。
Kei*_*ith 10
这对我有用:
$ nc www.rssweather.com 80
GET /wx/in/kanpur/wx.php HTTP/1.0
Host: www.rssweather.com
Run Code Online (Sandbox Code Playgroud)
然后点击double <enter>,即一次用于远程http服务器,一次用于nc命令.
在本地进行测试 python3 http.server
这也是一种有趣的测试方法。在一个外壳上,启动本地文件服务器:
python3 -m http.server 8000
Run Code Online (Sandbox Code Playgroud)
然后在第二个外壳上,发出一个请求:
printf 'GET / HTTP/1.1\r\nHost: localhost\r\n\r\n' | nc localhost 8000
Run Code Online (Sandbox Code Playgroud)
的Host:报头中需要HTTP 1.1。
这将显示目录的HTML列表,就像您从中看到的那样:
firefox http://localhost:8000
Run Code Online (Sandbox Code Playgroud)
接下来,您可以尝试列出文件和目录并观察响应:
printf 'GET /my-subdir/ HTTP/1.1\n\n' | nc localhost 8000
printf 'GET /my-file HTTP/1.1\n\n' | nc localhost 8000
Run Code Online (Sandbox Code Playgroud)
每次成功请求时,服务器都会打印:
127.0.0.1 - - [05/Oct/2018 11:20:55] "GET / HTTP/1.1" 200 -
Run Code Online (Sandbox Code Playgroud)
确认已收到。
example.com
这个由IANA维护的域是另一个很好的测试URL:
printf 'GET / HTTP/1.1\r\nHost: example.com\r\n\r\n' | nc example.com 80
Run Code Online (Sandbox Code Playgroud)
并与以下网址进行比较:http : //example.com/
https SSL协议
nc似乎无法处理https网址。相反,您可以使用:
sudo apt-get install nmap
printf 'GET / HTTP/1.1\r\nHost: github.com\r\n\r\n' | ncat --ssl github.com 443
Run Code Online (Sandbox Code Playgroud)
另请参阅:https : //serverfault.com/questions/102032/connecting-to-https-with-netcat-nc/650189#650189
如果尝试nc,它会挂起:
printf 'GET / HTTP/1.1\r\nHost: github.com\r\n\r\n' | nc github.com 443
Run Code Online (Sandbox Code Playgroud)
并尝试端口80:
printf 'GET / HTTP/1.1\r\nHost: github.com\r\n\r\n' | nc github.com 443
Run Code Online (Sandbox Code Playgroud)
只是给出对https版本的重定向响应:
HTTP/1.1 301 Moved Permanently
Content-Length: 0
Location: https://github.com/
Connection: keep-alive
Run Code Online (Sandbox Code Playgroud)
在Ubuntu 18.04上测试。
您甚至不需要使用/安装netcat
使用fd
exec 88<>/dev/tcp/rssweather.com/80
echo -e "GET /dir/Asia/India HTTP/1.1\nhost: www.rssweather.com\nConnection: close\n\n" >&88
sed 's/<[^>]*>/ /g' <&88
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
66494 次 |
| 最近记录: |