Mar-14-2021, 05:13 AM
Hi, I have a program I'm trying to switch modules from http.client to requests. The program takes a website through input and scans the index file to determine what filetype it is, pretty simple.
My issue is now that I switched to the requests module when I give it a website to scan it's telling me the index is all the possible filetypes so something is going wrong somewhere. I've been messing around and looking for answers for a few hours now so I figured somebody here might be able to tell me why.
I would guess it's somewhere between line 23 & 30.
My issue is now that I switched to the requests module when I give it a website to scan it's telling me the index is all the possible filetypes so something is going wrong somewhere. I've been messing around and looking for answers for a few hours now so I figured somebody here might be able to tell me why.
I would guess it's somewhere between line 23 & 30.
#import http.client
import requests
files = ['index.html','index.php','index.js']
html = ["index.html", "Index is a html file"]
php = ["index.php", "Index is a php file"]
js = ["index.js", "Index is a javascript file"]
site = input("Enter URL-> ")
print ("Scanning " + "{}...\n".format(site))
print ("-"*60)
# HTTP.Client function
#def connection_status(site, index_file):
# connection = http.client.HTTPSConnection(site)
# connection.request("HEAD", index_file)
# return connection.getresponse().status
# Requests fuction
def connection_status(site):
connection = requests.head(site)
return connection.status_code
def scan(site, upload):
status = connection_status(site)
if status == 200:
if upload == "index.html":
print (html[0])
print (html[1])
print ("-"*60)
elif upload == "index.php":
print (php[0])
print (php[1])
print ("-"*60)
elif upload == "index.js":
print (js[0])
print (js[1])
print ("-"*60)
else:
pass
else:
pass
for upload in files:
scan(site, upload)
print ("")
print ("Scan complete!")
print ("")
exit()Output:Scanning http://localhost/...
------------------------------------------------------------
index.html
Index is a html file
------------------------------------------------------------
index.php
Index is a php file
------------------------------------------------------------
index.js
Index is a javascript file
------------------------------------------------------------
Scan complete!The index file in my localhost is index.html so that's all I'm expecting to return. Thanks to anyone taking the time to read this thread!
