Python socket.RCVALL_ON() Examples

The following are 3 code examples for showing how to use socket.RCVALL_ON(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

You may also check out all available functions/classes of the module socket , or try the search function .

Example 1
Project: Offensive-Security-Certified-Professional   Author: StevenDias33   File: host-scanner-via-udp.py    License: MIT License 5 votes vote down vote up
def main(argv):
    global BIND

    if len(argv) < 3:
        print('Usage: ./udp-scan.py <bind-ip> <target-subnet>')
        sys.exit(1)

    bindAddr = sys.argv[1]
    subnet = sys.argv[2]

    sockProto = None
    if os.name == 'nt':
        sockProto = socket.IPPROTO_IP
    else:
        sockProto = socket.IPPROTO_ICMP

    sniffer = socket.socket(socket.AF_INET, socket.SOCK_RAW, sockProto)
    if DEBUG: print('[.] Binding on {}:0'.format(bindAddr))
    sniffer.bind((bindAddr, 0))

    # Include IP headers in the capture
    sniffer.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)

    # In Windows, set up promiscous mode.
    if os.name == 'nt':
        try:
            sniffer.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
        except socket.error, e:
            print('[!] Could not set promiscous mode ON: "{}"'.format(str(e)))

    # Sending thread 
Example 2
Project: mmvt   Author: pelednoam   File: udp_listener.py    License: GNU General Public License v3.0 5 votes vote down vote up
def listen_raw():
    # http://stackoverflow.com/questions/1117958/how-do-i-use-raw-socket-in-python
    HOST = socket.gethostbyname(socket.gethostname())
    s = socket.socket(socket.AF_INET, socket.SOCK_RAW)
    # s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    # s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
    s.bind((HOST, PORT))
    # s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
    while True:
        x = s.recvfrom(2048)
        print(x)
    s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)


# def main(args):
#     cmd = '{} -m src.udp.udp_listener -f start_udp_listener -b {}'.format(args.python_cmd, args.buffer_size)
#     out_queue, in_queue = mu.run_command_in_new_thread(
#         cmd, read_stderr=False, read_stdin=False, stdout_func=reading_from_rendering_stdout_func)
#
#
#     while True:
#         stdout_print('listening to stdin!')
#         line = sys.stdin.read()
#         if line != '':
#             stdout_print('UDP listener: received "{}"'.format(line))
#             if line == 'stop':
#                 stdout_print('Stop listening')
#                 udp_listening = False
#
#     # except:
#     #     print(traceback.format_exc())
#
# 
Example 3
Project: dizzy   Author: ernw   File: eth.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def open(self):
        try:
            if CONFIG["GLOBALS"]["PLATFORM"] == "Windows":
                from socket import SIO_RCVALL, RCVALL_ON
                self.s = socket(AF_INET, SOCK_RAW, IPPROTO_IP)
                host = gethostbyname(gethostname())
                self.s.bind((host, 0))
                # enable promisc
                self.s.ioctl(SIO_RCVALL, RCVALL_ON)
            else:
                self.s = socket(PF_PACKET, SOCK_RAW, self.ETH_P_ALL)
                # set interface
                self.s.bind((self.interface, self.ETH_P_ALL))
                # enable promisc
                import fcntl
                self.ifr = Ifreq()
                ifname = create_string_buffer(self.interface.encode(CONFIG["GLOBALS"]["CODEC"]))
                self.ifr.ifr_ifrn = ifname.value
                fcntl.ioctl(self.s.fileno(), self.SIOCGIFFLAGS, self.ifr)  # G for Get
                self.ifr.ifr_flags |= self.IFF_PROMISC
                fcntl.ioctl(self.s.fileno(), self.SIOCSIFFLAGS, self.ifr)  # S for Set
            self.maxsize = 1500
        except Exception as e:
            raise SessionException("session/eth: cant open session: %s" % e)
        else:
            self.is_open = True