標籤:無線 erro int prefix rom bin sock 0.12 bsp
1.列印本機裝置名稱以及IPv4地址
#!/usr/bin/python2.7
# -*- coding=utf-8 -*-import socket
def print_machine_info():
host_name = socket.gethostname() #本機裝置名稱
ip_address = socket.gethostbyname(host_name) #裝置名稱對應的ip 地址
print "%s \‘s ip is %s" % (host_name,ip_address) #列印
if __name__ == ‘__main__‘:
print_machine_info()
2.擷取遠程裝置的IP地址資訊
#!/usr/bin/python2.7
import socket
def print_machine_info():remote_hostname = ‘www.baidu.com‘ try:print "%s \‘s ip is %s" % (remote_hostname,socket.gethostbyname(remote_hostname)) except socket.error, err_msg: print "%s: %s" %(remote_hostname, err_msg)
if __name__ == ‘__main__‘:print_machine_info()
3.計算cisco無線AP需要dhcp的option43
#/usr/bin/python2.7# -*- coding=utf-8 -*-import socketfrom binascii import hexlifyimport sysdef wlc_option43_hex():
wlc_number = raw_input(‘Enter the wlc number:‘) if wlc_number == ‘1‘: put_number = raw_input(‘Enter the wlc ip:‘)for ip_addr in [put_number]: wlc_ip_addr = socket.inet_aton(ip_addr) unpacked_ip_addr = socket.inet_ntoa(wlc_ip_addr)hex_prefix = ‘f104‘print "IP Address: %s => option43 hex %s"\%(unpacked_ip_addr,str(hex_prefix)+hexlify(wlc_ip_addr)) else:while True:put_number = raw_input(‘Enter the wlc ip:‘)if put_number!= ‘q‘:for ip_addr in [put_number]: wlc_ip_addr = socket.inet_aton(ip_addr) unpacked_ip_addr = socket.inet_ntoa(wlc_ip_addr)hex_prefix = ‘f108‘print "IP Address: %s => option43 hex %s"\%(unpacked_ip_addr,str(hex_prefix)+hexlify(wlc_ip_addr)) else:sys.exit()if __name__ == ‘__main__‘:wlc_option43_hex()
效果:
當無線控制器的數量為1時:
Enter the wlc number:1
Enter the wlc ip:10.10.9.252
IP Address: 10.10.9.252 => option43 hex f1040a0a09fc
當無線控制器的數量為2時:
Enter the wlc number:2
Enter the wlc ip:10.10.8.252
IP Address: 10.10.8.252 => option43 hex f1080a0a08fc
Enter the wlc ip:10.10.123.252
IP Address: 10.10.123.252 => option43 hex f1080a0a7bfc
Enter the wlc ip:q
python網路編程學習2016/11/18