sfhttp.py
· 959 B · Python
Raw
#!/usr/bin/env python3
from requests import post as _post
import urllib3
urllib3.disable_warnings(category=urllib3.exceptions.InsecureRequestWarning)
def post(*args, **kwargs):
kwargs["verify"] = False
# if not "headers" in kwargs:
# kwargs["headers"] = {}
# kwargs["headers"]["Content-Type"] = "application/json"
return _post(*args, **kwargs)
def query(host, port, function, data={}):
if function == "HealthCheck":
data = {"ClientCustomData": ""}
return post(f"https://{host}:{port}/api/v1", json={"function": function, "data": data}).json()
def main():
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("host")
parser.add_argument("function")
parser.add_argument("--port", default=7777, type=int)
args = parser.parse_args()
print(query(args.host, args.port, args.function))
return 0
if __name__ == "__main__":
from sys import exit
exit(main())
| 1 | #!/usr/bin/env python3 |
| 2 | from requests import post as _post |
| 3 | import urllib3 |
| 4 | urllib3.disable_warnings(category=urllib3.exceptions.InsecureRequestWarning) |
| 5 | |
| 6 | def post(*args, **kwargs): |
| 7 | kwargs["verify"] = False |
| 8 | # if not "headers" in kwargs: |
| 9 | # kwargs["headers"] = {} |
| 10 | # kwargs["headers"]["Content-Type"] = "application/json" |
| 11 | return _post(*args, **kwargs) |
| 12 | |
| 13 | def query(host, port, function, data={}): |
| 14 | if function == "HealthCheck": |
| 15 | data = {"ClientCustomData": ""} |
| 16 | return post(f"https://{host}:{port}/api/v1", json={"function": function, "data": data}).json() |
| 17 | |
| 18 | def main(): |
| 19 | from argparse import ArgumentParser |
| 20 | parser = ArgumentParser() |
| 21 | parser.add_argument("host") |
| 22 | parser.add_argument("function") |
| 23 | parser.add_argument("--port", default=7777, type=int) |
| 24 | args = parser.parse_args() |
| 25 | print(query(args.host, args.port, args.function)) |
| 26 | return 0 |
| 27 | |
| 28 | if __name__ == "__main__": |
| 29 | from sys import exit |
| 30 | exit(main()) |
| 31 |