Created
July 11, 2016 13:10
-
-
Save anton-khodak/cd24a5a547d93516307b6969955d8c50 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import json | |
import socket | |
import netifaces | |
import requests | |
interfaces = netifaces.interfaces() | |
mac_adresses = [] | |
for interface in interfaces: | |
for i in list(netifaces.ifaddresses(interface).values()): | |
mac_addr = i[0]['addr'] | |
if all((len(x) == 2) for x in mac_addr.split(':')) and not mac_addr.startswith('00:'): | |
mac_adresses.append({'mac': mac_addr}) | |
def get_ip(): | |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
try: | |
# doesn't even have to be reachable | |
s.connect(('10.255.255.255', 0)) | |
IP = s.getsockname()[0] | |
except: | |
IP = '127.0.0.1' | |
finally: | |
s.close() | |
return IP | |
data = { | |
"common": { | |
"version": "1.0", | |
"api_key": "AKBmg1cBAAAAunBKbAIAIIS3jBIvzC1euqHu296B0Y5GvFEAAAAAAAAAAACX2qBiWPdsmHd5XfTAoc_kGa_v-w==" | |
}, | |
"wifi_networks": [ | |
{ | |
"mac": "00-1C-F0-E4-BB-F5", | |
"signal_strength": -88, | |
"age": 0, | |
} | |
], | |
# "wifi_networks": mac_adresses, | |
# "ip": { | |
# "address_v4": get_ip() | |
# } | |
} | |
print(data) | |
data = json.dumps(data) | |
r = requests.post('http://api.lbs.yandex.net/geolocation', data={'json': data}) | |
print(r.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment