1, statistical system remaining memory.
2, according to the existing MAC address, write a MAC address 1 larger than the previous MAC address.
1, Statistics system remaining memory (Linux for example)
#!/usr/bin/env python#-*-coding:utf-8-*-with open ('/proc/meminfo ') as F: For line in F.xreadlines (): if Line.startswith (' Memtotal '): Total = Int (Line.split () [1]) total/=1024.0 continue if Line.startswith (' Memfree '): Free = Int (Line.split () [1]) free/=1024.0 breakprint ' machine total memory%.2fm '% print ' remaining memory total%.2fm '% (free) print ' remaining memory consumption percent%.2f '% (free/total)
2, according to the existing MAC address, write a MAC address 1 larger than the previous MAC address.
#!/usr/bin/env python#-*-coding:utf-8-*-macaddr = ' 00:16:3d:00:30:ad ' #获取mac地址最后一段end = macaddr[-2:] #将16进制转换为10进制n = Int (end,16) #在10进制数值的基础上加1n = n + # Converts the newly produced 10-digit number to 16-binary, and the 16-binary starts with 0x, so remove it. New_end = Hex (n). Strip (' 0x ') #判断new_end的长度. Because if the last paragraph is 01 such that less than 10 of the 16 binary, it means that my newly generated 16 binary is removed after 0x will be only 1 digits, so write to the MAC address is one less. If Len (new_end) <2:new_end = ' 0 ' + new_end new_macaddr = macaddr[:-2] + new_end.upper () print new_macaddr
The last problem is to figure out 16 binary and 10 binary conversion is no problem.
1, convert the 16 binary to 10 binary int (' a ', +) int (' 0xa ',) 0x is the 16-binary front identifier 2, convert 10 to 16 hex (10)
Python Small Example