1. Print the native device name and IPV4 address
#!/usr/bin/python2.7
#-*-Coding=utf-8-*-import socket
Def print_machine_info ():
HOST_NAME = Socket.gethostname () #本机设备名
ip_address = Socket.gethostbyname (host_name) # The IP address corresponding to the device name
Print "%s \ ' s IP is%s"% (host_name,ip_address) # Printing
if __name__ = = ' __main__ ':
Print_machine_info ()
2. Get the IP address information for the remote device
#!/usr/bin/python2.7
Import socket
Def print_machine_info ():Remote_hostname = ' www.baidu.com 'TryPrint "%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. Calculate the Cisco wireless APs require 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))ElseWhile 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))ElseSys.exit ()if __name__ = = ' __main__ ':Wlc_option43_hex ()
Effect:
When the number of wireless controllers is 1 o'clock:
Enter the WLC number:1
Enter the WLC ip:10.10.9.252
IP address:10.10.9.252 = option43 Hex F1040A0A09FC
When the number of wireless controllers is 2 o'clock:
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 Network Programming Learning 2016/11/18