Beispiel #1
0
 def process_data(self, data, captured):
     handler, eth_hdr, ip_hdr = self._get_handler(data)
     ip = None
     if handler is not None:
         if ip_hdr is not None:
             ip = int(ip_hdr.src.encode('hex'), 16)
         mac = int(eth_hdr.src.encode('hex'), 16)
         try:
             key, query, sub_type = handler.process(eth_hdr, ip_hdr)
             captured = datetime.datetime.fromtimestamp(captured)
             Request.create(type=key, query=query, ip=ip, mac=mac, captured=captured, sub_type=sub_type)
         except:
             print 'here'
def get_logs(hid):
  retj = Request.create('GET', f'https://api.arrowconnect.io/api/v1/kronos/devices/{hid}/logs', {
    '_size' : 200
  })
  if not retj['data']: return
  for entry in retj['data']:
    #print(json.dumps(entry, indent=2))
    c_type = entry['type']
    if c_type not in ('SendCommand', 'ApiMethod'):
      print(f"{hid}, ct: {c_type}")
    p = entry['parameters']

    estr = ''
    if c_type == 'ApiMethod':
      event = p['apiName']
      cmd = p['apiMethodName']
      estr = f"{event}:{cmd}"
    elif c_type == 'UpdateDevice':
      estr = c_type
    elif p.get('eventName'):
      event = p['eventName']
      cmd = p['command']
      estr = f"{event}:{cmd}"
    else:
      print(json.dumps(entry, indent=2))
      sys.exit(0)


    if not seen.get(estr):
      print(hid, c_type, estr)
    seen[estr] = 1 + seen.get(estr,0)
def hid(cmd):
  retj = Request.create('GET', f'https://api.arrowconnect.io/api/v1/kronos/devices/91bddfcd3e7ef7227c2a7eb40771c415affddc5c/{cmd}', {
    #'_size': 200,
    #'_page': pagenum,
    'statuses': True,
  })
  print(json.dumps(retj, indent=2))
Beispiel #4
0
    def __update_or_save(self, save_params):
        request = Request(self, params=save_params)
        url = self.base_url()

        if self.persisted:
            url += '/' + self.id
            response = request.update(url)
        else:
            response = request.create(url)
        return response
def all_gateways():
  pagenum = 0
  totcount = 0
  while True:
    retj = Request.create('GET', 'https://api.arrowconnect.io/api/v1/kronos/gateways', {
      '_size': 200,
      '_page': pagenum,
    })
    pagecount = len(retj['data'])
    if not pagecount: break
    totcount += pagecount
    print(f"got page {pagenum}, count {totcount}")

    pagenum += 1
Beispiel #6
0
def send_url(q, i):
    global sock
    global mutex
    while True:
        url = q.get()
        if url is None:
            break
        json_data = Request.create(method='GET', text=url)
        try:
            with mutex:
                # print(time.time(),'send i   ',json_data)
                sock.send(json_data.encode(code))
        except socket.timeout:
            print('send data timeout')
        except socket.error as ex:
            # print('send data error', ex)
            break
def all_devices():
  pagenum = 0
  totcount = 0
  while True:
    retj = Request.create('GET', 'https://api.arrowconnect.io/api/v1/kronos/devices', {
      '_size': 200,
      '_page': pagenum,
    })
    pagecount = len(retj['data'])
    if not pagecount: break
    totcount += pagecount
    print(f"got page {pagenum}, count {totcount}")
    for dev in retj['data']:
      hid = dev['hid']
      #print(hid)
      get_logs(hid)

    pagenum += 1
  print(seen)
#  /devices

# kronos/nodes (customers, basically)
# kronos/nodes/types (staging level)
# kronos/rtu/find (two entries, firmware)
# kronos/software/releases/schedules (zillions)

# to test: telemetry, device-action-api
# kronos/devices/actions/types



if False and True:
  retj = Request.create('GET', f'https://api.arrowconnect.io/api/v1/{cmd}', {
    #'_size': 200,
    #'_page': pagenum,
    #'statuses': True,
  })
  print(json.dumps(retj, indent=2))

def hid(cmd):
  retj = Request.create('GET', f'https://api.arrowconnect.io/api/v1/kronos/devices/91bddfcd3e7ef7227c2a7eb40771c415affddc5c/{cmd}', {
    #'_size': 200,
    #'_page': pagenum,
    'statuses': True,
  })
  print(json.dumps(retj, indent=2))

def all_gateways():
  pagenum = 0
  totcount = 0
Beispiel #9
0
    re.IGNORECASE)

result = ''

url = input()

validate = (re.match(regex, url))
while True and not validate:
    print('Try plz again')
    url = input()
    validate = (re.match(regex, url))

with socket.create_connection(('127.0.0.1', 10002), 10) as sock:
    sock.settimeout(10)
    try:
        json_data = Request.create(method='GET', url=url)
        sock.sendall(json_data.encode(code))
    except socket.timeout:
        print('send data timeout')
    except socket.error as ex:
        print('send data error', ex)

    while True:
        try:
            data = sock.recv(1024)
            if data:
                result += data.decode(code)
        except socket.timeout:
            # print('get data timeout')
            break
        except socket.error as ex: