Advertisement
Guest User

Untitled

a guest
Feb 17th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.32 KB | None | 0 0
  1. #!/bin/python
  2.  
  3. import MySQLdb
  4.  
  5.  
  6. class Database:
  7.  
  8.    host= "localhost"              
  9.    user="root"
  10.    password="up2date4u"
  11.    db="packetAnalyzer"
  12.  
  13.    def __init__(self):  
  14.       self.connection = MySQLdb.connect(self.host, self.user, self.password, self.db)
  15.       self.cursor = self.connection.cursor()
  16.  
  17.    def insert(self, query):
  18.  
  19.        try:
  20.            self.cursor.execute(query)
  21.            self.connection.commit()
  22.            global inserted
  23.            inserted = inserted +1
  24.            print "sucess"
  25.        except:
  26.            self.connection.rollback()
  27.            global failed
  28.            print "failed"
  29.            print query
  30.            raw_input("")
  31.            failed = failed +1
  32.  
  33.    def query(self, query):
  34.        cursor = self.connection.cursor( MySQLdb.cursors.DictCursor )
  35.        cursor.execute(query)
  36.        return cursor.fetchall()
  37.  
  38.    def queryone(self, query):
  39.       cursor = self.connection.cursor( MySQLdb.cursors.DictCursor )
  40.       cursor.execute(query)
  41.       numbers = cursor.fetchone()
  42.       return numbers    
  43.  
  44.    def __del__(self):
  45.        self.connection.close()
  46.  
  47.  
  48.  
  49. #while True:
  50. db = Database()
  51. network_id = 1
  52. query ="SELECT nextConversation from showPackets_networks where id = %s" %network_id
  53. convo = db.queryone(query)
  54. convo = convo["nextConversation"]
  55.  
  56. while True:
  57.    query = "SELECT * from showPackets_tcppackets where conversationID = 0  order by packetTime limit 1"
  58.    numbers = db.queryone(query)
  59.    if numbers < 1:
  60.       break
  61.  
  62.    sIP = numbers["sIP"]
  63.    dIP = numbers["dIP"]
  64.    dPORT = numbers["dPORT"]
  65.    sPORT = numbers["sPORT"]
  66.  
  67.  
  68.    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)
  69.    rows = db.query(query)
  70.    for row in rows:
  71.       packetID = row["id"]
  72.       print packetID
  73.       query = "UPDATE showPackets_tcppackets set conversationID=%s where id=%s" %(convo, packetID)
  74.       db.insert(query)
  75.    convo = convo + 1
  76.    print "convo is %s " % str(convo + 1)
  77.    raw_input("")
  78. print convo
  79. #query = "UPDATE showPackets_networks set nextConversation=%s where id=%s"%(convo, network_id)
  80. #db.insert(query)
  81.  
  82. #"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