-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0731e8
commit 049c684
Showing
5 changed files
with
93 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
0 <body> | ||
<blockquote> | ||
<b>Device Info -- DHCP Leases</b> | ||
<br><br> | ||
<table border="1" cellpadding="4" cellspacing="0"> | ||
<tr> | ||
<td class="hd">Hostname</td> | ||
<td class="hd">MAC Address</td> | ||
<td class="hd">IP Address</td> | ||
<td class="hd">Expires In</td> | ||
|
||
</tr> | ||
<tr><td>mint</td><td>e4:d5:3d:ea:7b:fd</td><td>192.168.10.2</td><td>16 hours, 41 minutes, 11 seconds</td></tr> | ||
<tr><td>android-2c50b1fcad09c5e9</td><td>5c:2e:59:4d:33:67</td><td>192.168.10.3</td><td>22 hours, 53 minutes, 7 seconds</td></tr> | ||
<tr><td>DESKTOP-TH9GRP6</td><td>64:5a:04:8d:38:ec</td><td>192.168.10.4</td><td>23 hours, 1 minutes, 2 seconds</td></tr> | ||
<tr><td>android-498d8e6d29d110c4</td><td>b4:52:7e:0e:2c:b9</td><td>192.168.10.5</td><td>22 hours, 55 minutes, 45 seconds</td></tr> | ||
<tr><td>personal</td><td>e4:d5:3d:e9:14:99</td><td>192.168.10.6</td><td>22 hours, 20 minutes, 27 seconds</td></tr> | ||
<tr><td>android-84539c235ad90e87</td><td>f4:0e:22:35:49:76</td><td>192.168.10.7</td><td>23 hours, 34 minutes, 36 seconds</td></tr> | ||
<tr><td>android-ad1ed1745e771f93</td><td>84:11:9e:17:f5:64</td><td>192.168.10.8</td><td>21 hours, 7 minutes, 54 seconds</td></tr> | ||
<tr><td>android-1e353a26d08c9d3e</td><td>a0:32:99:ab:33:31</td><td>192.168.10.9</td><td>23 hours, 25 minutes, 22 seconds</td></tr> | ||
|
||
</table> | ||
<script language="javascript"> | ||
lang_tran(MENU_DEVICE_INFO,5,''); | ||
</script> | ||
</blockquote> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import bs4, re, requests | ||
|
||
f = open('dhcpinfo.html', 'r') | ||
soup = bs4.BeautifulSoup(f, 'lxml') | ||
class Router(object): | ||
''' | ||
A PTCL router class. | ||
''' | ||
mac_adr_regex = re.compile(r'^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$') | ||
|
||
|
||
def __init__(self, mask="192.168.1.1", username="admin", password="admin"): | ||
self.mask = "http://" + mask + '/' | ||
self.username = username | ||
self.password = password | ||
self.dev_info = {} | ||
self.active_dev = [] # Active Devices on Wi-Fi | ||
self.host_and_mac = [] # Mac Addresses and Hostnames | ||
self.session = requests.Session() | ||
self.session.auth = (self.username, self.password) | ||
self.sessionKey = "" | ||
|
||
|
||
def dhcpinfo(self): | ||
''' | ||
Gets information from dhcp i.e., Mac Adresses and Hostnames. | ||
''' | ||
|
||
td = soup.findAll('td') | ||
for i in td: | ||
if self.mac_adr_regex.search(i.text): | ||
''' | ||
The HTML page contains hostnames and mac addresses right next | ||
to each other in the form of table. We search in the tables list | ||
(td) until a mac address is found, then appends it to the | ||
mac_address list. The hostname is located before it so by using | ||
index less than the current index of mac address, we obtain the | ||
hostname and append it to the dev_hostname list. | ||
''' | ||
# Before mac_addresses, there is hostname | ||
# After mac_addresses, there are local ip and expire time for | ||
# the device connected | ||
hostname = td[td.index(i) - 1].text | ||
self.dev_info["Hostname"] = hostname | ||
self.dev_info[hostname] = [i.text, td[td.index(i) + 1].text, td[td.index(i) + 2].text] | ||
return (self.dev_info) | ||
f.close() | ||
|
||
if __name__ == '__main__': | ||
ptcl = Router() | ||
s = ptcl.dhcpinfo() | ||
print (s['mint']) |