-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpexist.py
More file actions
25 lines (21 loc) · 746 Bytes
/
httpexist.py
File metadata and controls
25 lines (21 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import http.client
print("** This program returns 'exist' if the specific resource exists **\n")
host = input("Insert the host/IP: ")
port = int(input("Insert the port (default:80): "))
resource = input("Insert the resource you want to GET")
if (port == ""):
port = 80
try:
connection = http.client.HTTPConnection(host, port)
connection.request('GET', resource)
response = connection.getresponse()
print("Status = ", response.status)
if (response.status == 200):
print("** EXISTS **")
elif (response.status == 302 or response.status == 301):
print('** REDIRECTED **')
else:
print("Doesn't exist")
connection.close()
except ConnectionRefusedError:
print('Connection failed!')