不同网络层级的简单调试 2021-09-04

2021-09-04  本文已影响0人  9_SooHyun

总览

telnet

成功的telnet

telnet samba.example.com 445
Trying 172.31.25.31...
Connected to samba.example.com.
Escape character is '^]'.

有时,Connected to TargetHost后,会在稍后自动断开,提示信息为

Connection closed by foreign host.

这说明Connected后,由于目标主机的安全策略等原因,Connection被目标主机断掉

curl

The command-line parser in curl always parses the entire line and you can put the options anywhere you like; they can also appear after the URL:

curl -vL http://example.com

curl http://example.com -Lv

curl http://example.com -L -v

此外,curl还可以用来分析http时延


full chain from http request to http response

curl命令支持以下阶段的时间统计:

time_namelookup : 从请求开始到DNS解析完成的耗时
time_connect : 从请求开始到TCP三次握手完成耗时
time_appconnect : 从请求开始到TLS握手完成的耗时
time_pretransfer : 从请求开始到向服务器发送第一个GET请求开始之前的耗时
time_redirect : 重定向时间,包括到内容传输前的重定向的DNS解析、TCP连接、内容传输等时间
time_starttransfer : 从请求开始到server端开始传输response的时间
time_total : 从请求开始到完成的总耗时

使用curl命令分析http时延分为2步:

    time_namelookup:  %{time_namelookup}\n
       time_connect:  %{time_connect}\n
    time_appconnect:  %{time_appconnect}\n
      time_redirect:  %{time_redirect}\n
   time_pretransfer:  %{time_pretransfer}\n
 time_starttransfer:  %{time_starttransfer}\n
                    ----------\n
         time_total:  %{time_total}\n

What this does:
-w "@curl-format.txt" tells cURL to use our format file
-o /dev/null redirects the output of the request to /dev/null
-s tells cURL not to show a progress meter

也可以不使用模版文件,直接在curl命令里键入输入模版,如:
curl -w '\ntime_namelookup=%{time_namelookup}\ntime_connect=%{time_connect}\ntime_appconnect=%{time_appconnect}\ntime_redirect=%{time_redirect}\ntime_pretransfer=%{time_pretransfer}\ntime_starttransfer=%{time_starttransfer}\ntime_total=%{time_total}\n\n' -o /dev/null -s -L https://www.nixops.me/
可直接执行看效果

curl使用二进制的payload
curl --request POST --data-binary @README http://localhost:6666 # 使用@符号可以从文件中读取数据作为参数
eg.

curl 'http://9.134.166.231:8080/webapi/v1/ExpandOrder/Create' \
-X 'POST' \
-H 'Content-Type: application/json;charset=utf-8' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'Accept-Language: zh-cn' \
-H 'Host: 9.134.166.231:8080' \
-H 'Origin: http://9.134.166.231:8080' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15' \
-H 'Referer: http://9.134.166.231:8080/' \
-H 'Content-Length: 463' \
-H 'Connection: keep-alive' \
-H 'Cookie: x_host_key=17f209a8ab4-c5e8d903d5f8a6a810b5c51dcc9670d854d27d2f' \
--data-binary $'{"expand_plan_id":4,"plan_type_name":"\u4e1a\u52a1\u81ea\u8eab","product_id":132,"module_path":"TKE\u4e1a\u52a1\u8fd0\u8425-\u4e1a\u52a1\u8fd0\u8425-[\u6d4b\u8bd5][\u6d4b\u8bd5]","if_partition":1,"number":1,"device_class":"c1","wan_rate":"","lan_rate":"\u5343\u5146","os":"os","inner_ip_num":1,"outer_ip_num":0,"logic_domain":"logic","switch_dt":0,"rack_dt":0,"city":"\u6df1\u5733","campus":"\u6df1\u5733-\u576a\u5c71","expand_reason":"t s t","expand_detail_explain":"test","admin":"xiuxianwen","creator":null,"bak_admin":"xiuxianwen”}'
上一篇 下一篇

猜你喜欢

热点阅读