python網路編程學習2016/11/18

來源:互聯網
上載者:User

標籤:無線   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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.