python2计算cisco无线AP需要dhcp的option43

#/usr/bin/python2.7
# -*- coding=utf-8 -*-
import socket
from binascii import hexlify
import sys
def 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'
result=hex_prefix+hexlify(wlc_ip_addr)
print "IP Address: %s => option43 hex %s"\
%(unpacked_ip_addr,result[0:4]+'.'+result[4:8]+'.'+result[8:]) 
else:
put_number1 = raw_input('Enter the wlc ip:')
for ip_addr1 in [put_number1]:
wlc_ip_addr1  = socket.inet_aton(ip_addr1)
unpacked_ip_addr1 = socket.inet_ntoa(wlc_ip_addr1)
hex_prefix = 'f108'
result1=hexlify(wlc_ip_addr1)
put_number2 = raw_input('Enter the wlc ip:')
for ip_addr2 in [put_number2]:
wlc_ip_addr2=socket.inet_aton(ip_addr2)
unpacked_ip_addr2 = socket.inet_ntoa(wlc_ip_addr2)
result2=hexlify(wlc_ip_addr2)
result = hex_prefix+result1+result2
print "IP Address: %s %s => option43 hex %s"\
%(unpacked_ip_addr1,unpacked_ip_addr2,result[0:4]+'.'+result[4:8]+'.'+result[8:12]+'.'+result[12:16]+'.'+result[16:])
if __name__ == '__main__':
wlc_option43_hex()
#一台cisco无线控制器 
#Enter the wlc number:1
#Enter the wlc ip:10.10.9.245
#IP Address: 10.10.9.245 => option43 hex f104.0a0a.09f5
#两台cisco无线控制器
#Enter the wlc number:2
#Enter the wlc ip:10.10.1.123
#Enter the wlc ip:10.10.1.124
#IP Address: 10.10.1.123 10.10.1.124 => option43 hex f108.0a0a.017b.0a0a.017c
posted on 2016-11-18 17:10  koalabear  阅读(1170)  评论(0编辑  收藏  举报