-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
45 lines (32 loc) · 1.11 KB
/
main.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
import netlas
import json
apikey = "enternetlasapi"
# create new connection to Netlas
netlas_connection = netlas.Netlas(api_key=apikey)
# Get user input for the query
d = input("Enter the domain: ")
netlas_query = netlas_connection.download(query="*."+d, datatype="domain",size=100,fields="domain")
count=0
def extract_domain(iterator):
for json_bytes in iterator:
# Decode the JSON bytes to a Python object
json_object = json.loads(json_bytes)
# Extract the domain value
domain = json_object['data']['domain']
# Yield the extracted domain value
yield domain
file_path = "lol.txt"
try:
# Step 1: Open the file in write mode
with open(file_path, "w") as file:
# Step 2: Write data to the file
for domain in extract_domain(netlas_query):
count=count+1
file.write(domain+"\n")
except FileNotFoundError:
print(f"The file '{file_path}' was not found.")
except IOError as e:
print(f"An error occurred while writing to the file: {e}")
else:
print(f"Data has been successfully written to {file_path}.")
print(count)