Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/python
- import MySQLdb
- class Database:
- host= "localhost"
- user="root"
- password="up2date4u"
- db="packetAnalyzer"
- def __init__(self):
- self.connection = MySQLdb.connect(self.host, self.user, self.password, self.db)
- self.cursor = self.connection.cursor()
- def insert(self, query):
- try:
- self.cursor.execute(query)
- self.connection.commit()
- global inserted
- inserted = inserted +1
- print "sucess"
- except:
- self.connection.rollback()
- global failed
- print "failed"
- print query
- raw_input("")
- failed = failed +1
- def query(self, query):
- cursor = self.connection.cursor( MySQLdb.cursors.DictCursor )
- cursor.execute(query)
- return cursor.fetchall()
- def queryone(self, query):
- cursor = self.connection.cursor( MySQLdb.cursors.DictCursor )
- cursor.execute(query)
- numbers = cursor.fetchone()
- return numbers
- def __del__(self):
- self.connection.close()
- #while True:
- db = Database()
- network_id = 1
- query ="SELECT nextConversation from showPackets_networks where id = %s" %network_id
- convo = db.queryone(query)
- convo = convo["nextConversation"]
- while True:
- query = "SELECT * from showPackets_tcppackets where conversationID = 0 order by packetTime limit 1"
- numbers = db.queryone(query)
- if numbers < 1:
- break
- sIP = numbers["sIP"]
- dIP = numbers["dIP"]
- dPORT = numbers["dPORT"]
- sPORT = numbers["sPORT"]
- query = "SELECT id from showPackets_tcppackets where sIP = '%s' and dIP = '%s' and dPORT = %s and sPORT = %s order by packetTime" % (sIP, dIP, dPORT, sPORT)
- rows = db.query(query)
- for row in rows:
- packetID = row["id"]
- print packetID
- query = "UPDATE showPackets_tcppackets set conversationID=%s where id=%s" %(convo, packetID)
- db.insert(query)
- convo = convo + 1
- print "convo is %s " % str(convo + 1)
- raw_input("")
- print convo
- #query = "UPDATE showPackets_networks set nextConversation=%s where id=%s"%(convo, network_id)
- #db.insert(query)
- #"UPDATE showPackets_networks set tcpPackets=%s, udpPackets=%s, icmpPackets=%s, otherPackets=%s where id = %s"%(tcp, udp, icmp, other, network_id)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement