python mac地址转int,Python MAC地址 获取,过滤,转

【输出MAC 地址】[root@pc0003 glpi_switch_ocs]# cat huawei

#!/usr/bin/expect -f

set ip 192.168.AC.IP

set password AC.PASSWORD

set timeout 1

spawn ssh AC.USER@$ip

expect {

"*yes/no" { send "yes\r"; exp_continue}

"*password:" { send "$password\r" }

}

expect ""

send "sys\r"

expect "\[ac001\]"

send "wlan\r"

expect "wlan-view"

send "sta-whitelist-profile id 1\r"

expect "prof-vob***"

send "d th\r"

expect "More"

send "\t"

expect "More"

send "\t"

expect "More"

send "\t"

expect "More"

send "\t"

expect "More"

send "\t"

expect eof

#interact

[root@pc0003 glpi_switch_ocs]#

【过滤MAC地址】[root@pc0003 glpi_switch_ocs]# cat 1get.switch.wlan.grep.mac.sh

#!/bin/bash

# 此脚本正则匹配MAC,输出原格式的纯MAC地址

#指定分割符

split="-"

mkdir tmp > /dev/null 2>&1

./huawei |grep "sta-mac" > ./tmp/huawei.mac.txt

stat=`echo $?`

if [ $stat==0 ]

then

echo "已获取到交换机mac白名单"

else

echo "与交换机联络失败"

fi

#1a?2b?3d?4g?5k?6h

#cat mac.txt | egrep -o "([0-9a-fA-F]{2})(([/\s$split][0-9a-fA-F]{2}){5})" > mac.txt

#1qaz?2wsx?3edc

cat ./tmp/huawei.mac.txt | egrep -o "([0-9a-fA-F]{4})(([/\s$split][0-9a-fA-F]{4}){2})" > ./tmp/grep.switch.mac.txt

stat=`echo $?`

if [ $stat==0 ]

then

echo "纯MAC地址文件已经输出: ./tmp/grep.switch.mac.txt"

echo "格式如下"

head ./tmp/grep.switch.mac.txt

fi

【MAC地址转换】#!/usr/bin/python

new1=open('./tmp/convert.switch','w')

import re

import os

r1=r"\w\w\w\w-\w\w\w\w-\w\w\w\w"

for i in open('./tmp/grep.switch.mac.txt'):

str_upper=i.upper()

string1=str(re.findall(r1,str_upper))

list1=list(string1)

while '[' in list1:

list1.remove('[')

while '\'' in list1:

list1.remove('\'')

while '-' in list1:

list1.remove('-')

while ']' in list1:

list1.remove(']')

new1.write(list1[0]+list1[1]+":"+list1[2]+list1[3]+":"+list1[4]+list1[5]+":"+list1[6]+list1[7]+":"+list1[8]+list1[9]+":"+list1[10]+list1[11]+"\n")

new1.close()

【获取GLPI的MAC地址】[root@pc0003 glpi_switch_ocs]# cat 3get.glpi.sh

#!/bin/bash

# 此脚本正则匹配MAC,输出原格式的纯MAC地址

mkdir tmp > /dev/null 2>&1

#指定分割符

split=":"

mysql -h 192.168.GLPI.MYSQL.IP -pGLPI.MYSQL.PASSWORD  -Ne "use glpi;select glpi_items_devicenetworkcards.mac from glpi_items_devicenetworkcards,glpi_devicenetworkcards  where glpi_items_devicenetworkcards.devicenetworkcards_id = glpi_devicenetworkcards.id;" > tmp/glpi.all.mac

stat=`echo $?`

if [ $stat==0 ]

then

echo "已获取到glpi的mac所有清单"

else

echo "与mysql联络失败!"

fi

#1a?2b?3d?4g?5k?6h

cat tmp/glpi.all.mac | egrep -o "([0-9a-fA-F]{2})(([/\s$split][0-9a-fA-F]{2}){5})" > tmp/grep.glpi.mac.txt

stat=`echo $?`

if [ $stat==0 ]

then

echo "纯MAC地址文件已经输出:./tmp/grep.glpi.mac.txt"

echo "格式如下"

head ./tmp/grep.glpi.mac.txt

fi

[MAC地址转换]#!/usr/bin/python

new1=open('./tmp/convert.glpi.mac','w')

import re

r1=r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w"

for i in open('tmp/grep.glpi.mac.txt'):

str_upper=i.upper()

string1=str(re.findall(r1,str_upper))

list1=list(string1)

while '[' in list1:

list1.remove('[')

while '\'' in list1:

list1.remove('\'')

while ':' in list1:

list1.remove(':')

while ']' in list1:

list1.remove(']')

print list1

new1.write(list1[0]+list1[1]+":"+list1[2]+list1[3]+":"+list1[4]+list1[5]+":"+list1[6]+list1[7]+":"+list1[8]+list1[9]+":"+list1[10]+list1[11]+"\n")

new1.close()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值