Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GNU nano 1.3.12 File: dl_handler.py
- #!/usr/bin/env python26
- # -*- coding: utf-8 -*-
- """snmp handler for d-link 3028 ver 0.1"""
- import re
- import sys
- import string
- import MySQLdb
- db = MySQLdb.connect("localhost","login","pass","basename")
- cursor = db.cursor()
- data = sys.stdin.read()
- to_str = data
- ip_switch = re.findall('10.40.[0-9]{1,3}.[0-9]{1,3}', to_str)
- ips = ip_switch[0]
- mac_port_type = re.findall('".*?"', to_str)
- pmt = mac_port_type[0][1:-1].replace(" ",'')
- change_type = pmt[:2]
- mac_address = pmt[2:-6]
- port = int(pmt[16:-2],16)
- to_sql = {'a':ips, 'b':change_type,'c':mac_address,'d':port}
- sql = """INSERT INTO main(SWITCH_IP,
- CLIENT_MAC, CLIENT_PORT, CHANGE_TYPE)
- VALUES ('%(a)s', '%(c)s', '%(d)s', '%(b)s')"""% to_sql
- try:
- cursor.execute(sql)
- db.commit()
- except:
- db.rollback()
- db.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement