-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpywifi.py
executable file
·107 lines (83 loc) · 3.5 KB
/
pywifi.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
#!/usr/bin/env python
'''
This script returns values regarding the current wi-fi connection
Documentation:
https://developer.apple.com/library/mac/documentation/CoreWLAN/Reference/CWInterface_reference/translated_content/CWInterface.html
objc framework import referenced from:
http://stackoverflow.com/questions/12136817/how-do-you-use-pyobjc-to-turn-off-and-on-the-wireless-interfaces-of-a-mac
'''
##############################################################################
# Copyright 2014 Joseph Chilcote
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy
# of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
##############################################################################
import objc
objc.loadBundle('CoreWLAN',
bundle_path='/System/Library/Frameworks/CoreWLAN.framework',
module_globals=globals())
class WiFi(object):
''' WiFI object'''
def __init__(self):
self.wifi = CWInterface.interfaceNames()
for iname in self.wifi:
self.interface = CWInterface.interfaceWithName_(iname)
self.ip_monitor = self.interface.ipMonitor()
self.last_network_joined = self.interface.lastNetworkJoined()
def get_wifistatus(self):
if self.interface.powerOn() == 1:
return "Yes"
return "No"
def get_ssid(self):
return self.interface.ssid()
def get_interface(self):
return self.interface.interfaceName()
def get_hardwareaddress(self):
return self.interface.hardwareAddress()
def get_aggregatenoise(self):
return self.interface.aggregateNoise()
def get_aggregaterssi(self):
return self.interface.aggregateRSSI()
def get_bssid(self):
return self.interface.bssid()
def get_channel(self):
return self.interface.channel()
def get_transmitrate(self):
return self.interface.transmitRate()
def get_mcsindex(self):
return self.interface.mcsIndex()
def get_security(self):
return self.interface.securityMode()
def get_ipaddress(self):
return self.ip_monitor.ipv4Addresses()[0]
def get_last_network_joined(self):
return self.last_network_joined.ssid()
def get_last_tethered_device(self):
return self.interface.lastTetherDeviceJoined()
def main():
wifi = WiFi()
print 'Interface: %s' % wifi.get_interface()
print 'Hardware Address: %s' % wifi.get_hardwareaddress()
print 'Active: %s' % wifi.get_wifistatus()
print 'SSID: %s' % wifi.get_ssid()
print 'Aggregate Noise: %s' % wifi.get_aggregatenoise()
print 'BSSID: %s' % wifi.get_bssid()
print 'RSSI: %s' % wifi.get_aggregaterssi()
print 'Channel: %s' % wifi.get_channel()
print 'Transmit Rate: %s' % wifi.get_transmitrate()
print 'MCS Index: %s' % wifi.get_mcsindex()
print 'Security: %s' % wifi.get_security()
print 'IP Address: %s' % wifi.get_ipaddress()
print 'Last Network Joined: %s' % wifi.get_last_network_joined()
print 'Last Tethered Device Joined: %s' % wifi.get_last_tethered_device()
if __name__ == "__main__":
main()