Example #1
1
    def main(self):
        options = {"TCP": False, "ICMP": False, "UDP": False, "OTHER": False}
        devices = pcapy.findalldevs()
        print devices
        print chr(27) + "[0;91m" + "[!]" + chr(27) + "[0m" + " Dispositivos disponibles:"
        for d in devices:
            print " -> " + d

        dev = raw_input(chr(27) + "[0;92m" + "[+]" + chr(27) + "[0m" + " Introduzca el nombre del dispositivo: ")

        print chr(27) + "[0;91m" + "[!]" + chr(27) + "[0m" + " Dispositivo seleccionado: " + dev

        cap = pcapy.open_live(dev, 65536, 1, 0)
        options = raw_input(chr(27) + "[0;92m" + "[+]" + chr(27) + "[0m" + " Introduzca las opciones:")
        if options == "ALL":
            options = {"TCP": True, "ICMP": True, "UDP": True, "OTHER": True}
        else:

            lista_options = tuple(options.split(","))
            for opcion in lista_options:
                if opcion in options:
                    options[opcion] = True
                else:
                    print "[-] Protocolo incorrecto."

        # Empezamos a sniffar paquetes
        while 1:
            (header, packet) = cap.next()
            self.parse_packet(packet, options)
Example #2
1
def intlist_to_bytes(xs):
    if not xs:
        return b""
    if isinstance(chr(0), bytes):  # Python 2
        return "".join([chr(x) for x in xs])
    else:
        return bytes(xs)
def getheader(im, info=None):
    """Return a list of strings representing a GIF header"""

    optimize = info and info.get("optimize", 0)

    s = [
        "GIF87a"
        + o16(im.size[0])  # magic
        + o16(im.size[1])  # size
        + chr(7 + 128)
        + chr(0)  # flags: bits + palette
        + chr(0)  # background  # reserved/aspect
    ]

    if optimize:
        # minimize color palette
        i = 0
        maxcolor = 0
        for count in im.histogram():
            if count:
                maxcolor = i
            i = i + 1
    else:
        maxcolor = 256

    # global palette
    if im.mode == "P":
        # colour palette
        s.append(im.im.getpalette("RGB")[: maxcolor * 3])
    else:
        # greyscale
        for i in range(maxcolor):
            s.append(chr(i) * 3)

    return s
Example #4
1
 def test_isupper(self, size):
     chars = "".join([chr(c) for c in range(255) if not chr(c).islower()])
     repeats = size // len(chars) + 2
     s = chars * repeats
     self.failUnless(s.isupper())
     s += "a"
     self.failIf(s.isupper())
Example #5
1
def b58decode(v, length):
    """ decode v into a string of len bytes
  """
    long_value = 0L
    for (i, c) in enumerate(v[::-1]):
        long_value += __b58chars.find(c) * (__b58base ** i)

    result = ""
    while long_value >= 256:
        div, mod = divmod(long_value, 256)
        result = chr(mod) + result
        long_value = div
    result = chr(long_value) + result

    nPad = 0
    for c in v:
        if c == __b58chars[0]:
            nPad += 1
        else:
            break

    result = chr(0) * nPad + result
    if length is not None and len(result) != length:
        return None

    return result
Example #6
1
    def __init__(self):
        rospy.init_node("pololu_driver")
        rospy.on_shutdown(self.ShutdownCallback)
        rospy.Subscriber("/cmd_vel", Twist, self.SteeringCallback)
        port = ["/dev/ttyACM0", "/dev/ttyACM3"]
        self.ser = []
        self.timeoutmax = 1000
        self.timeout = self.timeoutmax
        try:
            self.ser.append(serial.Serial(port[0]))
            self.ser[0].open()
            self.ser[0].write(chr(0xAA))
            self.ser[0].flush()
        except serial.serialutil.SerialException as e:
            rospy.logerr(rospy.get_name() + ": Error opening or initialising port " + port[0])
            exit(1)

        try:
            self.ser.append(serial.Serial(port[1]))
            self.ser[1].open()
            self.ser[1].write(chr(0xAA))
            self.ser[1].flush()
        except serial.serialutil.SerialException as e:
            rospy.logerr(rospy.get_name() + ": Error opening or initialising port " + port[1])
            exit(1)

        self.IdentifyPorts()
Example #7
0
def get_command(target):
    cmdbyte = chr(0x85)
    if target < 0:
        cmdbyte = chr(0x86)
    target = target * -1
    serialBytes = cmdbyte + chr(target & 0x1F) + chr((target >> 5) & 0x7F)
    return serialBytes
Example #8
0
    def completions(self, s):
        """
        Return all commands that complete the command starting with the
        string s.

        EXAMPLES::

            sage: c = giac.completions('cas')  # optional - giac
            sage: 'cas_setup' in c             # optional - giac
            True
        """
        bs = chr(8) * len(s)
        if self._expect is None:
            self._start()
        E = self._expect
        E.sendline("%s%s%s" % (s, chr(63), chr(13)))
        t = E.timeout
        E.timeout = 0.3  # since some things have no completion
        try:
            E.expect("----")
        except pexpect.TIMEOUT:
            E.timeout = t
            return []
        E.timeout = t
        v = E.before
        E.expect(self._prompt)
        E.expect(self._prompt)
        return v.split()[1:]
Example #9
0
 def setup(
     self,
     code="",
     constants_i=[],
     constants_r=[],
     constants_f=[],
     num_regs_i=255,
     num_regs_r=255,
     num_regs_f=255,
     liveness=None,
     startpoints=None,
     alllabels=None,
     resulttypes=None,
 ):
     self.code = code
     # if the following lists are empty, use a single shared empty list
     self.constants_i = constants_i or self._empty_i
     self.constants_r = constants_r or self._empty_r
     self.constants_f = constants_f or self._empty_f
     # encode the three num_regs into a single char each
     assert num_regs_i < 256 and num_regs_r < 256 and num_regs_f < 256
     self.c_num_regs_i = chr(num_regs_i)
     self.c_num_regs_r = chr(num_regs_r)
     self.c_num_regs_f = chr(num_regs_f)
     self.liveness = make_liveness_cache(liveness)
     self._startpoints = startpoints  # debugging
     self._alllabels = alllabels  # debugging
     self._resulttypes = resulttypes  # debugging