python - convert uint32 into readable values -


hello writing api communicate network manager on ubuntu. when ask ip address dbus service return :

broadcast_add = dbus.uint32(4278298816l, variant_level=1) 

what doing far converting 32 bit binary :

in [1]: '{0:0<32}'.format(bin(broadcast_add)[2:]) out[1]: '11111111000000011010100011000000' 

is there straightforward way convert uint32 readable ip address like

192.168.1.255 

if can access value 4278298816, might try use struct, example:

>>> import struct >>> >>> struct.unpack('<bbbb', struct.pack('<i', 4278298816)) (192, 168, 1, 255) >>> >>> '{}.{}.{}.{}'.format(*_) '192.168.1.255' >>> 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -