美文网首页
不同网络层级的简单调试 2021-09-04

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

作者: 9_SooHyun | 来源:发表于2021-09-04 23:21 被阅读0次

总览

  • ping host 检查网络层是否可达
  • telnet host port 检查传输层是否可达,即目标端口是否打开
  • curl -v host[:port] 检查应用层服务是否正常
  • wget --spider host[:port] 检查应用层服务是否正常

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 option

    • -v, --verbose 显示更丰富的信息,如请求头、请求体、响应头、响应体

    • -L, --location 用于自动重定向

      (HTTP) If the server reports that the requested page has moved to a different location (indicated with a Location: header and a 3XX
      response code), this option will make curl redo the request on the new place. If used together with -i, --include or -I, --head, headers from all requested pages will be shown. When authentication is used, curl only sends its credentials to the initial host. If a redirect takes curl to a different host, it won't be able to intercept the user+password(curl发现重定向还是会带账户密码过去). See also --location-trusted on how to change this.

    • -k, --insecure 无需校验服务器证书
      (TLS) By default, every SSL connection curl makes is verified to be secure. This option allows curl to proceed and operate even for server connections otherwise considered insecure.

    • -d, --data < data > 设置post请求体
      (HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded.

      Example:

      curl -d '{"id": 21868, "name":"testname"}' http://example.com/
      
    • -H, --header < header/@file > 设置请求头参数

      This option can be used multiple times to add/replace/remove multiple headers.

      Example:

      curl -H "X-First-Name: Joe" -H "X-Last-Name: James" http://example.com/
      

此外,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步:

  • 1.touch curl_format.txt作为模版文件,并写入如下内容
    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”}'

相关文章

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

    总览 ping host 检查网络层是否可达 telnet host port 检查传输层是否可达,即目标端口是否...

  • 网络分层环境下的程序运行原理

    如果大家简单了解过网络运行的原理的话应该都知道,网络协议是分为不同的层级结构的,下面我们就通过案例分析来了解一下,...

  • BP神经网络

    BP神经网络 一、BP神经网络 神经网络能很好地解决不同的机器学习问题。神经网络模型是许多逻辑单元按照不同层级组织...

  • 路由器行业解决方案应用

    路由器在运营商应用场景 路由器在各个行业的应用场景差不多,大体可分为4个网络层级,在不同的层级起着不同的作用,我们...

  • 1.Tomcat使用IDEA远程Debug调试的讲解

    JAVA 支持调试功能,本身提供了一个简单的调试工具JDB,支持设置断点及线程级的调试同时,不同的JVM通过接口的...

  • 不同层级的激励

    不同层级的管理激励机制,最重要的是执行,激励方案通过 名,利,权三方面,普惠金融家不同级别分别设置,非常注重细节,...

  • 设计的不同层级

    好用比好看更重要 刚开始学做设计时候,每天都会看dribbble和behance上优秀作品,看到那些优美的配色,炫...

  • 自律的不同层级

    人的自律有不同的层级,西游记中成佛前的的孙悟空,需要靠紧箍咒来约束自己,有些时候自己控制不了自己,得受紧箍咒的约束...

  • Flink文档 - 数据流编程模型

    抽象层级 Flink提供了几个不同的抽象层级来开发流处理/批处理应用程序。 最底层抽象简单的提供了状态流处理。该功...

  • 读书笔记-失控

    先做简单的事 学会准确无误的做简单的事 在简单任务的成果之上添加新的活动层级 不要改变简单事物 让新层级像简单层级...

网友评论

      本文标题:不同网络层级的简单调试 2021-09-04

      本文链接:https://www.haomeiwen.com/subject/rvmdwltx.html