-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.py
62 lines (48 loc) · 1.72 KB
/
cli.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
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
import argparse
from tqdm import tqdm
from harvest.ip import IP
from harvest.fetcher import Fetcher
parser = argparse.ArgumentParser(
usage="cli.py log_directory --write filename [attributes]")
parser.add_argument("path", type=str,
help="The path to your log directory")
parser.add_argument("-w", "--write", type=str, metavar=("path", "attribute"), nargs="+",
help="Write output to path")
args = parser.parse_args()
harvester = Fetcher(args.path)
with open("config", "r") as config_file:
for line in config_file:
key, value = line.strip().split(":")
if "token" in key and value is not "":
harvester = Fetcher(args.path, value)
for ip in tqdm(harvester.fetched, leave=False, ascii=True):
ip.populate()
def print_addresses(harvester: Fetcher):
for ip in harvester.fetched:
print(f"""
IP: {ip.address}
Location: {ip.loc}
Hostname: {ip.hostname}
City: {ip.city}
Region: {ip.region}
Country: {ip.country}
Organization: {ip.org}
Timezone: {ip.timezone}
Tor: {ip.tor}
""")
print(f"Amount: {len(harvester.fetched)}")
def write(args_list):
with open(args.write[0], "w") as file:
for ip in harvester.fetched:
for key in args_list[1:]:
file.write(
f"{key}: {getattr(ip, key)}\n") if hasattr(ip, key) else None
if key is args_list[-1]:
file.write("-"*30+"\n")
def main():
print_addresses(harvester)
if args.write:
write(args.write)
if __name__ == "__main__":
main()