Python Network Programming Learning 2016/11/18

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.