#!/usr/bin/python from gi.repository import Gtk from gi.repository import NMClient, NetworkManager from gi.repository import GLib import dbus from dbus.mainloop.glib import DBusGMainLoop dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) import struct import socket class C(object): def __init__(self): self.client = NMClient.Client.new() self.rs = NMClient.RemoteSettings() def set_cb(self): GLib.timeout_add(300, self.run) def run(self): print "RUN!" devs = self.client.get_devices() wireddevs = [dev for dev in devs if dev.get_device_type() == NetworkManager.DeviceType.ETHERNET] if not wireddevs: return dev = wireddevs[0] ipv4cfg = dev.get_ip4_config() ipaddress = ipv4cfg.get_addresses()[0].get_address() for ipaddr in [ipaddress, 16777216L, 10L]: print type(ipaddr) print ipaddr packed = struct.pack('!L', ipaddr) print "!L>%s<" % packed result = socket.inet_ntoa(packed) print result packed = struct.pack('=L', ipaddr) print "=L>%s<" % packed result = socket.inet_ntoa(packed) print result packed = struct.pack('L', ipaddr) print "L>%s<" % packed result = socket.inet_ntoa(packed) print result Gtk.main_quit() if __name__ == "__main__": c = C() c.set_cb() Gtk.main()