使用Bash发出POST请求

编程入门 行业动态 更新时间:2024-10-25 20:31:02
本文介绍了使用Bash发出POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我必须登录才能配置100个Jetpack.我正在尝试以bash脚本执行此操作,但是我没有运气.我可以连接到wifi没问题,但是我的POST请求没有实现任何事情.有什么建议吗?这是我的github的链接.我有在Burp套件中捕获的内容的副本 github/Jdelgado89/post_Script

I have a 100 Jetpacks that I have to sign in to configure. I am trying to do it in a bash script but I am having no luck. I can connect to the wifi no problem but my POST request are not achieving anything. Any Advice? Here is link to my github. I have copies of what I captured on Burp suite github/Jdelgado89/post_Script

TYIA

#!/bin/bash nmcli device wifi rescan nmcli device wifi list echo "What's they last four?" read last4 echo "What's the Key?" read key nmcli device wifi connect Ellipsis\ \Jetpack\ $last4 password $key echo "{"Command":"SignIn","Password":"$key"}" > sign_on.json echo "{"CurrentPassword":"$key","NewPassword":"G1l4River4dm1n","SecurityQuestion":"NameOfStreet","SecurityAnswer":"Allison"}" > change_admin.json echo "{"SSID":"GRTI Jetpack","WiFiPassword":"G1l4River3r","WiFiMode":0,"WiFiAuthentication":6,"WiFiEncription":4,"WiFiChannel":0,"MaxConnectedDevice":8,"PrivacySeparator":false,"WMM":true,"Command":"SetWifiSetting"}" > wifi.json cat sign_on.json cat change_admin.json cat wifi.json sleep 5 curl -X POST -H "Cookie: jetpack=6af5e293139d989bdcfd66257b4f5327" -H "Content-Type: application/json" -d @sign_on.json 192.168.1.1/cgi-bin/sign_in.cgi sleep 5 curl -X POST -H "Cookie: jetpack=6af5e293139d989bdcfd66257b4f5327" -H "Content-Type: application/json" -d @change_admin.json 192.168.1.1/cgi-bin/settings_admin_password.cgi sleep 5 curl -X POST -H "Cookie: jetpack=6af5e293139d989bdcfd66257b4f5327" -H "Content-Type: application/json" -d @wifi.json 192.168.1.1/cgi-bin/settings_admin_password.cgi

推荐答案

这是不正确的:

echo "{"Command":"SignIn","Password":"$key"}" > sign_on.json

双引号并没有直接放在文件中,它们只是终止以前一个双引号开头的shell字符串.这就是写作

The double quotes are not being put literally into the file, they're just terminating the shell string beginning with the previous double quote. So this is writing

{Command:SignIn,Password:keyvalue}

放入文件中,不带双引号.您需要转义嵌套的双引号.

into the file, with no double quotes. You need to escape the nested double quotes.

echo "{\"Command\":\"SignIn\",\"Password\":\"$key\"}" > sign_on.json

但是,最好使用 jq 实用程序,而不要手工格式化JSON.请参见使用jq创建JSON文件.

However, it would be best if you used the jq utility instead of formatting JSON by hand. See Create JSON file using jq.

jq -nc --arg key "$key" '{"Command":"SignIn","Password":$key}' >sign_on.json

更多推荐

使用Bash发出POST请求

本文发布于:2023-10-10 01:31:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1477324.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Bash   POST

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!