def __repr__(self): return ( "disk metrics:\n" + "\tdata transferred (read,written): {} , {}\n".format( utils.bytes_to_string(self.bytes_read), utils.bytes_to_string(self.bytes_written)) + "\tutilization: {:.2f}%\n".format(self.utilization() * 100) + "\teffective throughput: {}/s\n".format(utils.bytes_to_string(self.effective_throughput_Bps())) )
def __repr__(self): return ( "network metrics:\n" + "\tdata transmitted: {}\n".format(utils.bytes_to_string(self.bytes_transmitted)) + "\ttransmit utilization: {:.2f}%\n".format(self.transmit_utilization * 100) + "\teffective transmit throughput: {}/s ({}/s)\n".format( utils.bits_to_string(self.effective_transmit_throughput_Bps * 8), utils.bytes_to_string(self.effective_transmit_throughput_Bps)) )
def is_code_type(self, code): try: code_type = bytes_to_string(self.data[0:3]) return True if code_type == code else False except PCapException as e: if DEBUG: print(e.__str__())
def set_current_file_name(self): if b'\r' in self.data: self.data = self.data[:self.data.index(b'\r')] response = bytes_to_string(self.data) r = re.compile('for (.*?) \(') m = r.search(response) if m: FTPParser.current_file_name = m.group(1)
def parse_queries(self): pos = 12 for I in range(0, self.questions): name, pos = read_til_zero(self.data, pos) self.queries.append({ 'name': bytes_to_string(name), 'type': self.data[pos:pos + 2], 'class': self.data[pos + 2:pos + 4], }) pos += 4 return pos
def parse_queries(self): pos = 12 for I in range(0, self.questions): name, pos = read_til_zero(self.data, pos) self.queries.append({ 'name': bytes_to_string(name), 'type': self.data[pos:pos+2], 'class': self.data[pos+2:pos+4], }) pos += 4 return pos
def parse(self): super().parse() pos = 0 while pos < self.packet_size: part, pos = read_til(self.data, pos, b'\x0d\x0a') part = bytes_to_string(part) # TODO: kostyl, use analyzer self.check_state(part) if SMTPParser.session_state == self.DATA_STATE: SMTPParser.current_mail_data += part # TODO: end kostyl self.parts.append(part) self.processed = self.packet_size
def parse(self): super().parse() char_data = bytes_to_string(self.data[:self.packet_size]) lines = char_data.splitlines() if len(lines) > 0: parsed = self.parse_starting_line(lines[0]) if parsed: # TODO: kostyl, use analyzer self.set_current_file_name() # TODO: end kostyl empty_str_index = self.parse_headers(lines) self.parse_body(empty_str_index + 1, lines) else: self.parse_body(0, lines) self.processed = self.packet_size # TODO: kostyl, use analyzer HTTPParser.current_file += self.body # TODO: end kostyl else: raise InvalidHttpFormat()
def get_default_connection_info(self): self.remove_pending() connections_list = self.ActiveConnections conns = map(lambda path: self.to_object(path, klass=NMConnectionActive), connections_list) c_vpn, c_default = None, None for cn in conns: state = cn.State # print cn.Uuid, state if state != NM_ACTIVE_CONNECTION_STATE_ACTIVATED: log.debug("Adding connection %s to pending", cn.get_object_path()) non_active = self.to_object(cn.get_object_path(), klass=NMConnectionActive, receive_signals=True) non_active.add_listener("PropertiesChanged", self.on_conn_state_change) self.pending_connections.append(non_active) continue if cn.Vpn: c_vpn = cn break if cn.Default: c_default = cn c = c_vpn or c_default if not c: log.warn("Cannot get vpn or default connection") return None conn_info = {} conn_info["vpn"] = c.Vpn settings = self.to_object(c.Connection, klass=NMConnection).GetSettings() type = settings["connection"]["type"] conn_info["type"] = type conn_info["name"] = settings["connection"]["id"] ssid = None if type == "802-11-wireless": ssid = settings.get(type) and settings.get(type).get("ssid") ssid = utils.bytes_to_string(ssid) if type == "802-11-wireless" or type == "802-3-ethernet": mac = settings.get(type) and settings.get(type).get("mac-address") mac = utils.bytes_to_mac(mac) if mac: conn_info["mac"] = mac ip4_setup = settings.get("ipv4") and settings.get("ipv4").get("method") devices = c.Devices if len(devices) > 1: log.warn("We cannot work with more devices on connection %s, will use first one", conn_info["name"]) if not devices: raise NMError("Active connection %s does not have any devices", conn_info["name"]) device = self.to_object(devices[0], klass=NMDevice) conn_info["interface"] = device.Interface ip_addr2 = utils.ip4_to_str(device.Ip4Address) # conn_info['ip4']=utils.ip4_to_str(device.Ip4Address) dev_type = device.DeviceType conn_info["device_type"] = NM_DEVICE_TYPES_MAP.get(dev_type)[0] if dev_type == NM_DEVICE_TYPE_WIFI: spec_dev = device.get_specific_device() app_id = spec_dev.ActiveAccessPoint ap = self.to_object(app_id, klass=NMAccessPoint) try: ssid2 = utils.bytes_to_string(ap.Ssid) if ssid != ssid2: log.warn("SSIDs differ %s %s", ssid, ssid2) conn_info["ssid"] = ssid2 except Exception, e: log.warn("ssid error %s", e)
def parse_receiver(self): response = bytes_to_string(self.data) r = re.compile('To: (.*?)\r\n') m = r.search(response) if m: POP3Parser.receiver = m.group(1)
def parse_date(self): response = bytes_to_string(self.data) r = re.compile('Date: (.*?)\r\n') m = r.search(response) if m: POP3Parser.date = m.group(1)
def parse_subject(self): response = bytes_to_string(self.data) r = re.compile('Subject: (.*?)\r\n') m = r.search(response) if m: POP3Parser.subject = m.group(1)
def create_letter(self): new_line = '\r\n' return 'Sender: ' + self.sender + new_line + 'Receiver: ' + self.receiver + new_line \ + 'Date: ' + self.date + new_line + 'Subject: ' + self.subject + new_line + bytes_to_string(self.message)
def parse_sender(self): response = bytes_to_string(self.data) r = re.compile('From: (.*?)>') m = r.search(response) if m: POP3Parser.sender = m.group(1) + '>'