import kivy
kivy.require("1.9.0")
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.config import Config
import geocoder
import re
from uuid import getnode
Config.set("graphics", "multisamples", "0")
class MyNetworkDetailsLayout(GridLayout):
# pass
def get_mac(self):
# to get physical address:
original_mac_address = getnode()
return str(original_mac_address)
def get_hex_mac(self):
# to get physical address:
original_mac_address = getnode()
#print("MAC Address: " + str(original_mac_address)) # this output is in raw format
#convert raw format into hex format
hex_mac_address = str(":".join(re.findall('..', '%012x' % original_mac_address)))
#print("HEX MAC Address: " + hex_mac_address)
return str(hex_mac_address)
def get_main_ip(self):
geo_code = geocoder.ip("me")
ip_address = geo_code.ip
return str(ip_address)
# def get_local_ip(self):
# # to get IP address:
# ip_address = socket.gethostbyname(socket.gethostname())
# #self.display.text = str(ip_address)
# #print("IP Address: " + str(ip_address))
# return str(ip_address)
def get_latitude(self):
geo_code = geocoder.ip("me")
ip_address = geo_code.ip
latitude = geo_code.latlng[0]
return str(latitude)
def get_longitude(self):
geo_code = geocoder.ip("me")
ip_address = geo_code.ip
longitude = geo_code.latlng[1]
return str(longitude)
def get_city(self):
geo_code = geocoder.ip("me")
ip_address = geo_code.ip
locationCity = geo_code.geojson.get("features")[0].get("properties").get("city")
return str(locationCity)
def get_address(self):
geo_code = geocoder.ip("me")
ip_address = geo_code.ip
locationAddress = geo_code.geojson.get("features")[0].get("properties").get("address")
return str(locationAddress)
class NetworkDetailsApp(App):
def build(self):
return MyNetworkDetailsLayout()
networkapp = NetworkDetailsApp()
networkapp.run()
kivyfile:
<CustomButton@Button>:
font_size: 30
<MyNetworkDetailsLayout>:
id: networkDetails
# display: abc
rows: 7
padding: 10
spacing: 10
BoxLayout:
CustomButton:
id: macAddress1
text: "Machine Address"
Label:
font_size: 20
text:root.get_mac()
BoxLayout:
CustomButton:
id: macAddress1
text: "MAC Address"
Label:
font_size: 20
text:root.get_hex_mac()
BoxLayout:
CustomButton:
id: ipAddress1
text: "ISP IP Address"
Label:
font_size: 20
text:root.get_main_ip()
BoxLayout:
CustomButton:
id: ipAddress1
text: "Latitude"
Label:
font_size: 20
text:root.get_latitude()
BoxLayout:
CustomButton:
id: ipAddress1
text: "Longitude"
Label:
font_size: 20
text:root.get_longitude()
BoxLayout:
CustomButton:
id: ipAddress1
text: "City"
Label:
font_size: 20
text:root.get_city()
BoxLayout:
CustomButton:
id: ipAddress1
text: "Address"
Label:
font_size: 20
text:root.get_address()