Exemple #1
0
def write(line,table,devid):
  col = ['timestamp','ip','macid']
  
  try:
    line = line.split()
  except:
    return
  if len(line) < len(col):
    return
  cmd1 = 'INSERT into %s (deviceid,'%(table)
  cmd2 = 'VALUES ("%s",'%(devid)
  #print line
  for i in range(0,len(line)):
    quotes = '"'
    if i == 0:
      quotes = ''
    if i == col.index('ip'):
      quotes = ''
      line[i] = 'INET_ATON("%s")'%(line[i])
    cmd1 = '%s %s,'%(cmd1,col[i])
    cmd2 = '%s %s%s%s,'%(cmd2,quotes,line[i],quotes)
  cmd1 = cmd1[0:len(cmd1)-1]
  cmd2 = cmd2[0:len(cmd2)-1]
  cmd = '%s) %s)'%(cmd1,cmd2)
  print cmd
  sql.run_insert_cmd(cmd)
Exemple #2
0
def write(line,table,devid):
  col = {0:'TIMESTAMP',1:'ACTION',3:'IP',2:'MACID',4:'CLIENT'}
  
  try:
    line = line.split()
  except:
    return
  cmd1 = 'INSERT into %s (DEVICEID,'%(table)
  cmd2 = 'VALUES ("%s",'%(devid) 
  if len(line) < 4:
    return
  for i in range(0,len(line)):
    quotes = '"'
    if i == 0:
      quotes = ''
    if col[i] == 'IP':
      quotes = ''
      line[i] = 'INET_ATON("%s")'%(line[i])
    cmd1 = '%s %s,'%(cmd1,col[i])
    cmd2 = '%s %s%s%s,'%(cmd2,quotes,line[i],quotes)
  cmd1 = cmd1[0:len(cmd1)-1]
  cmd2 = cmd2[0:len(cmd2)-1]
  cmd = '%s) %s)'%(cmd1,cmd2)
  sql.run_insert_cmd(cmd)
  print cmd
Exemple #3
0
def write(line, table, devid):
    col = {0: 'TIMESTAMP', 1: 'ACTION', 3: 'IP', 2: 'MACID', 4: 'CLIENT'}

    try:
        line = line.split()
    except:
        return
    cmd1 = 'INSERT into %s (DEVICEID,' % (table)
    cmd2 = 'VALUES ("%s",' % (devid)
    if len(line) < 4:
        return
    for i in range(0, len(line)):
        quotes = '"'
        if i == 0:
            quotes = ''
        if col[i] == 'IP':
            quotes = ''
            line[i] = 'INET_ATON("%s")' % (line[i])
        cmd1 = '%s %s,' % (cmd1, col[i])
        cmd2 = '%s %s%s%s,' % (cmd2, quotes, line[i], quotes)
    cmd1 = cmd1[0:len(cmd1) - 1]
    cmd2 = cmd2[0:len(cmd2) - 1]
    cmd = '%s) %s)' % (cmd1, cmd2)
    sql.run_insert_cmd(cmd)
    print cmd
Exemple #4
0
def write(line,table,devid,events):
  col = ['timestamp','eventid']
  
  try:
    line = line.split()
  except:
    return
  if len(line) < len(col):
    return
  cmd1 = 'INSERT into %s (deviceid,'%(table)
  cmd2 = 'VALUES ("%s",'%(devid)
  #print line
  for i in range(0,len(line)):
    quotes = '"'
    if i < 2:
      quotes = ''
    if i == col.index('eventid'):
      line[i] = events[line[i]]
    cmd1 = '%s %s,'%(cmd1,col[i])
    cmd2 = '%s %s%s%s,'%(cmd2,quotes,line[i],quotes)
  cmd1 = cmd1[0:len(cmd1)-1]
  cmd2 = cmd2[0:len(cmd2)-1]
  cmd = '%s) %s)'%(cmd1,cmd2)
  print cmd
  sql.run_insert_cmd(cmd)
def write(head, body, devid, table):
    field2col = {
        "bssid": "BSSID",
        "first time seen": "FIRSTSEEN",
        "last time seen": "LASTSEEN",
        "channel": "CHANNEL",
        "speed": "SPEED",
        "cipher": "CIPHER",
        "privacy": "PRIVACY",
        "authentication": "AUTH",
        "power": "POWER",
        "# beacons": "NUMBEACONS",
        "# iv": "NUMIV",
        "lan ip": "LANIP",
        "id-length": "IDLEN",
        "essid": "ESSID",
        "key": "WKEY",
        "station mac": "STATIONMAC",
        "power": "POWER",
        "# packets": "NUMPKTS",
        "probed essids": "PROBEDESSID",
    }
    for i in range(0, len(body)):
        if len(body[i]) == 1:
            continue
        cmd1 = "INSERT into %s (DEVICEID," % (table)
        cmd2 = 'VALUES("%s",' % (devid)
        for j in range(0, len(head)):
            if head[j].lower() in ["lan ip", "key"]:
                continue
            quotes = '"'
            if head[j].lower() in ["channel", "speed", "power", "# beacons", "# iv", "id-length", "# packets"]:
                quotes = ""
            if head[j].lower() in ["first time seen", "last time seen"]:
                quotes = ""
                try:
                    body[i][j] = 'UNIX_TIMESTAMP("%s")' % (body[i][j])
                except:
                    continue
            try:
                cmd1 = "%s %s," % (cmd1, field2col[head[j].lower()])
            except:
                continue
            try:
                cmd2 = "%s %s%s%s," % (cmd2, quotes, body[i][j], quotes)
            except:
                continue
            # print '%s:%s '%(head[j],body[i][j]),
        cmd1 = cmd1[0 : len(cmd1) - 1]
        cmd2 = cmd2[0 : len(cmd2) - 1]
        cmd = "%s) %s)" % (cmd1, cmd2)
        print cmd
        sql.run_insert_cmd(cmd)
    return
Exemple #6
0
def write_block_v1_0(data, tables, log, file):
    if 'info' not in data:
        log.write('Error: No info field in %s\n' % (file))
        return
    flag = 0
    for tab in tables:
        if tab in data:
            flag = 1
            break
    if flag == 0:
        log.write('Error: No known fields in %s\n' % (file))
        return

    for tab in tables:
        if tab in data:
            numrec = len(data[tab])
            for i in range(0, numrec):
                table = tables[tab]
                fids = []
                vals = []
                if tab != 'hop':
                    fids, vals = get_measurement_params(
                        fids, vals, data['info'][0])
                else:
                    ttid = data[tab][i]['ttid']
                    data[tab][i].pop('ttid')
                    did = data['info'][0]['deviceid']
                    ts = data['traceroute'][ttid]['timestamp']
                    tid = get_id_from_table(tables['traceroute'], did, ts)
                    idtuple = {"tid": tid}
                    fids, vals = get_measurement_params(fids, vals, idtuple)

                fids, vals = get_measurement_params(fids, vals, data[tab][i])
                cmd = form_insert_cmd(table, fids, vals)
                res = sql.run_insert_cmd(cmd)
                cnt = 0
                while ((res == 0) and (cnt < 5)):
                    print "res ", res
                    time.sleep(.1)
                    res = sql.run_insert_cmd(cmd)
                    cnt += 1
                if res == 0:
                    log.write('Could not %s from %s\n' % (cmd, file))
Exemple #7
0
def write_block_v1_0(data,tables,log,file):
  if 'info' not in data:
    log.write('Error: No info field in %s\n'%(file))
    return
  flag = 0
  for tab in tables:
    if tab in data:
      flag = 1
      break
  if flag == 0:
    log.write('Error: No known fields in %s\n'%(file))
    return

  for tab in tables:
    if tab in data:
      numrec = len(data[tab])
      for i in range(0,numrec):
        table = tables[tab]
        fids = []
        vals = []
        if tab != 'hop':
          fids,vals = get_measurement_params(fids,vals,data['info'][0])
        else:
          ttid = data[tab][i]['ttid']
          data[tab][i].pop('ttid')
          did = data['info'][0]['deviceid']
          ts = data['traceroute'][ttid]['timestamp']
          tid = get_id_from_table(tables['traceroute'],did,ts)
          idtuple = {"tid":tid}
          fids,vals = get_measurement_params(fids,vals,idtuple)
        
        fids,vals = get_measurement_params(fids,vals,data[tab][i])
        cmd = form_insert_cmd(table,fids,vals)
        res = sql.run_insert_cmd(cmd)
        cnt = 0
        while ((res == 0) and (cnt < 5)):
          print "res ", res
          time.sleep(.1)   
          res = sql.run_insert_cmd(cmd)
          cnt += 1
        if res == 0:
          log.write('Could not %s from %s\n'%(cmd,file))
def write(head,body,devid,table):
  field2col = {"bssid":"BSSID","first time seen":"FIRSTSEEN",'last time seen':'LASTSEEN',\
               'channel':'CHANNEL','speed':'SPEED','cipher':'CIPHER','privacy':'PRIVACY',\
               'authentication':'AUTH','power':'POWER','# beacons':'NUMBEACONS','# iv':'NUMIV',\
               'lan ip':'LANIP','id-length':'IDLEN','essid':'ESSID','key':'WKEY','station mac':'STATIONMAC',\
               'power':'POWER','# packets':'NUMPKTS','probed essids':'PROBEDESSID'}
  for i in range(0,len(body)): 
    if len(body[i]) == 1:
      continue
    cmd1 = 'INSERT into %s (DEVICEID,'%(table)
    cmd2 = 'VALUES("%s",'%(devid)
    for j in range(0,len(head)):
      if head[j].lower() in ['lan ip','key']:
        continue
      quotes = '"'
      if head[j].lower() in ['channel','speed','power','# beacons','# iv','id-length','# packets']:
        quotes = ''
      if head[j].lower() in ['first time seen','last time seen']:
        quotes = ''
        try:
          body[i][j] = 'UNIX_TIMESTAMP("%s")'%(body[i][j])
        except:
          continue
      try:
        cmd1 = "%s %s,"%(cmd1,field2col[head[j].lower()])
      except:
        continue
      try:
        cmd2 = "%s %s%s%s,"%(cmd2,quotes,body[i][j],quotes)
      except:
        continue
      #print '%s:%s '%(head[j],body[i][j]),
    cmd1 = cmd1[0:len(cmd1)-1]
    cmd2 = cmd2[0:len(cmd2)-1]
    cmd = '%s) %s)'%(cmd1,cmd2)
    print cmd
    sql.run_insert_cmd(cmd)
  return