-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinforecon.py
54 lines (41 loc) · 1.28 KB
/
inforecon.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
"""Gathering Information
(1) Grabbing banners
(2) Hostname
(3) IP Lookup
Usage: $ python3 inforecon.py <url>
"""
import json
import socket
import sys
import requests
def get_url_info(url: str) -> str:
"""Gets a list of information from a url
Args:
url (str): The url of a website
Returns:
str: The headers, ip adress, and banners of a url
"""
try:
# Gets headers using requests
req = requests.get(f"https://{url}")
print(f"\n[+] Headers for <{url}>:")
for key, value in req.headers.items():
print(f"\t{key}: {value}")
# Gets ip address using socket
ipaddress = socket.gethostbyname(url)
print(f"\n[+] IP address of <{url}>: {ipaddress}")
# Gets api generated information
api_req = requests.get(f"https://ipinfo.io/{ipaddress}/json")
resp = json.loads(api_req.text)
print(f"\t[+] Ip info for <{url}>:")
for key, value in resp.items():
print(f"\t{key}: {value}")
except:
print(f"[-] Connection to <{url}> refused, exiting...")
sys.exit(1)
if __name__ == "__main__":
if len(sys.argv) < 2:
print(f"[!] Usage: python3 {sys.argv[0]} <url>")
sys.exit(1)
get_url_info(sys.argv[1])