Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions webcrab.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def sendrequest(r):
print(f"Missing required parameter {x} in request. \n\n{r}")
sys.exit()

if 'headers' not in 'r':
if 'headers' not in r:
r['headers']={}
if 'body' not in 'r':
if 'body' not in r:
r['body']=''
if 'port' in 'r':
if 'port' in r:
url = r['scheme']+'://'+r['host']+':'+r['port']+r['url']
else:
url = r['scheme']+'://'+r['host']+r['url']
Expand All @@ -51,21 +51,24 @@ def sendrequest(r):
sys.exit()
requestfile = sys.argv[1]
resultfile = sys.argv[2] + "." + str(int(time.time()))
data = None
try:
f = open(requestfile)
with open(requestfile) as f:
data = json.load(f)
except FileNotFoundError:
print(f"Can not find {requestfile}")
sys.exit()
try:
data = json.load(f)
except json.decoder.JSONDecodeError:
print(f"Error parsing '{requestfile}'")
sys.exit()
f.close()
f = open(resultfile,'a')
for r in data:
response = sendrequest(r)
f.write(jsonfy(response,r['comment']))
f.close()
except Exception as e:
print(f"Uncaught exception: {e}. Please open an issue at https://github.com/DShield-ISC/WebCrab/issues.")
if not data:
print(f"No data found in {requestfile}.")
sys.exit()
with open(resultfile,'a') as f:
for r in data:
response = sendrequest(r)
f.write(jsonfy(response,r['comment']))