Python fcntl.ioctl方法代码示例

本文整理汇总了Python中fcntl.ioctl方法的典型用法代码示例。如果您正苦于以下问题:Python fcntl.ioctl方法的具体用法?Python fcntl.ioctl怎么用?Python fcntl.ioctl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块fcntl的用法示例。

在下文中一共展示了fcntl.ioctl方法的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: mac_set_ip_address

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def mac_set_ip_address(self, dev, ip, serverip, netmask):
		ifr = struct.pack('<16sBBHIIIBBHIIIBBHIII',
			self.iface_name,
			16, socket.AF_INET, 0, struct.unpack('<L', socket.inet_pton(socket.AF_INET, ip))[0], 0, 0,
			16, socket.AF_INET, 0, struct.unpack('<L', socket.inet_pton(socket.AF_INET, serverip))[0], 0, 0,
			16, 0, 0, struct.unpack('<L', socket.inet_pton(socket.AF_INET, "255.255.255.255"))[0], 0, 0)
		try:
			sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
			fcntl.ioctl(sock, self.IOCTL_MACOSX_SIOCAIFADDR, ifr)
		except Exception as e:
			common.internal_print("Something went wrong with setting up the interface.", -1)
			print(e)
			sys.exit(-1)
		# adding new route for forwarding packets properly.
		integer_ip = struct.unpack(">I", socket.inet_pton(socket.AF_INET, serverip))[0]
		rangeip = socket.inet_ntop(socket.AF_INET, struct.pack(">I", integer_ip & ((2**int(netmask))-1)<<32-int(netmask)))
		ps = subprocess.Popen(["route", "add", "-net", rangeip+"/"+netmask, serverip], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
		(stdout, stderr) = ps.communicate()
		if stderr:
			if not "File exists" in stderr:
				common.internal_print("Error: adding client route: {0}".format(stderr), -1)
				sys.exit(-1)
		return 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:27,代码来源:interface.py


示例2: freebsd_tun_alloc

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def freebsd_tun_alloc(self, dev, flags):
		try:
			sockfd = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
			ifr = struct.pack('<16si', 'tun', 0)
			self.iface_name = fcntl.ioctl(sockfd, self.IOCTL_FREEBSD_SIOCIFCREATE2, ifr)
			self.iface_name = self.iface_name.rstrip("\x00")
			buff = array.array('c', dev+"\x00")
			caddr_t, _ = buff.buffer_info()
			ifr = struct.pack('16sP', self.iface_name, caddr_t);
			fcntl.ioctl(sockfd, self.IOCTL_FREEBSD_SIOCSIFNAME, ifr)
			tun = os.open("/dev/"+self.iface_name, os.O_RDWR | os.O_NONBLOCK)
			self.iface_name = dev
		except IOError as e:
			print e
			common.internal_print("Error: Cannot create tunnel. Is {0} in use?".format(dev), -1)
			sys.exit(-1)
		return tun 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:23,代码来源:interface.py


示例3: get_termsize

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def get_termsize():
    """Return terminal size as a tuple (height, width)."""
    try:
        # this works on unix machines
        import struct, fcntl, termios
        height, width = struct.unpack("hhhh",
                                      fcntl.ioctl(0,termios.TIOCGWINSZ,
                                                  "\000"*8))[0:2]
        if not (height and width):
            height, width = 24, 79
    except ImportError:
        # for windows machins, use default values
        # Does anyone know how to get the console size under windows?
        # One approach is:
        # http://code.activestate.com/recipes/440694/
        height, width = 24, 79
    return height, width 
开发者ID:ME-ICA,项目名称:me-ica,代码行数:19,代码来源:progress_bar.py


示例4: resize_handler

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def resize_handler(self):
        """Send the new window size to conmon."""
        def wrapped(signum, frame):  # pylint: disable=unused-argument
            packed = fcntl.ioctl(self.pseudo_tty.stdout, termios.TIOCGWINSZ,
                                 struct.pack('HHHH', 0, 0, 0, 0))
            rows, cols, _, _ = struct.unpack('HHHH', packed)
            logging.debug('Resize window(%dx%d) using %s', rows, cols,
                          self.pseudo_tty.control_socket)
            # TODO: Need some kind of timeout in case pipe is blocked
            with open(self.pseudo_tty.control_socket, 'w') as skt:
                # send conmon window resize message
                skt.write('1 {} {}\n'.format(rows, cols))
        return wrapped 
开发者ID:containers,项目名称:python-podman,代码行数:18,代码来源:_containers_attach.py


示例5: __connect

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def __connect(self):
        device_addr, hidraw_device, event_device = self.__find_device()
        if device_addr is None:
            return False
        self.__report_fd = os.open(hidraw_device, os.O_RDWR | os.O_NONBLOCK)
        self.__fd = FileIO(self.__report_fd, "rb+", closefd=False)
        self.__input_device = InputDevice(event_device)
        self.__input_device.grab()
        buf = bytearray(38)
        buf[0] = 0x02
        try:
            return bool(fcntl.ioctl(self.__fd, 3223734279, bytes(buf)))
        except:
            pass
        if self.recv():
            self.update_controller() 
开发者ID:notkarol,项目名称:derplearning,代码行数:18,代码来源:joystick.py


示例6: _get_terminal_size_linux

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def _get_terminal_size_linux():
    def ioctl_GWINSZ(fd):
        try:
            import fcntl
            import termios
            cr = struct.unpack('hh',
                               fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
            return cr
        except:
            pass
    cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
    if not cr:
        try:
            fd = os.open(os.ctermid(), os.O_RDONLY)
            cr = ioctl_GWINSZ(fd)
            os.close(fd)
        except:
            pass
    if not cr:
        try:
            cr = (os.environ['LINES'], os.environ['COLUMNS'])
        except:
            return None
    return int(cr[1]), int(cr[0]) 
开发者ID:aaronjanse,项目名称:asciidots,代码行数:26,代码来源:terminalsize.py


示例7: getLocalip

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def getLocalip(interface: str = "wlan0") -> str:
    """This function will return the Local IP Address of the interface"""
    if "nux" in sys.platform:
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        try:
            return socket.inet_ntoa(
                fcntl.ioctl(
                    s.fileno(), 0x8915, struct.pack('256s',interface[:15])
                )[20:24]
            )
        except IOError:
            print("{}[!] Error, unable to detect local ip address.".format(Colors.FAIL))
            print("[!] Check your connection to network {}".format(Colors.ENDC))
            exit()
    elif "darwin" in sys.platform:
        return [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][0] 
开发者ID:the-c0d3r,项目名称:pynmap,代码行数:18,代码来源:ip.py


示例8: read_byte_data

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def read_byte_data(self, addr, cmd):
        """Read a single byte from the specified cmd register of the device."""
        assert (
            self._device is not None
        ), "Bus must be opened before operations are made against it!"
        # Build ctypes values to marshall between ioctl and Python.
        reg = c_uint8(cmd)
        result = c_uint8()
        # Build ioctl request.
        request = make_i2c_rdwr_data(
            [
                (addr, 0, 1, pointer(reg)),  # Write cmd register.
                (addr, I2C_M_RD, 1, pointer(result)),  # Read 1 byte as result.
            ]
        )
        # Make ioctl call and return result data.
        ioctl(self._device.fileno(), I2C_RDWR, request)
        return result.value 
开发者ID:adafruit,项目名称:Adafruit_Python_PureIO,代码行数:20,代码来源:smbus.py


示例9: get_ip_address

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def get_ip_address(ifname):
  """
  Get the ip address from the specified interface.
    >>> get_ip_address('eth0')
    '192.168.0.7'
  @type ifname: string
  @param ifname: The interface name. Typical names are C{'eth0'},
  C{'wlan0'}, etc.
  @rtype: string
  @return: The IP address of the specified interface.
  """
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  return socket.inet_ntoa(fcntl.ioctl(
      s.fileno(),
      0x8915,  # SIOCGIFADDR
      struct.pack('256s', ifname[:15]))[20:24]) 
开发者ID:crigroup,项目名称:optitrack,代码行数:20,代码来源:utils.py


示例10: getAlarmElapsedRealTime

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def getAlarmElapsedRealTime():
    ### This method is used on Android to get the UP_TIME.
    elapsedTime = -1
    try:
         alarmFile = open("/dev/alarm", 'r')
         if alarmFile:
             t = timespec()
             # ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME) = 0x40086134
             result = fcntl.ioctl(alarmFile.fileno(), 0x40086134, t)
             if result == 0:
                 elapsedTime = t.tv_sec
             alarmFile.close()
    except Exception, e:
        log.error(e) 
开发者ID:sprinkler,项目名称:rainmachine-developer-resources,代码行数:18,代码来源:rmUtils.py


示例11: getAlarmElapsedRealTime

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def getAlarmElapsedRealTime():
    ### DEPRECATED: This method was used on Android to get the UP_TIME (replaced by monotonicTime())
    elapsedTime = -1
    try:
         alarmFile = open("/dev/alarm", 'r')
         if alarmFile:
             t = timespec()
             # ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME) = 0x40086134
             result = fcntl.ioctl(alarmFile.fileno(), 0x40086134, t)
             if result == 0:
                 elapsedTime = t.tv_sec
             alarmFile.close()
    except Exception, e:
        log.error(e) 
开发者ID:sprinkler,项目名称:rainmachine-developer-resources,代码行数:18,代码来源:rmTimeUtils.py


示例12: send_IOCTL

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def send_IOCTL(ioc, device_name = "wlan0"):
		# This code is untested, because our target (BCM43430a1) talks NETLINK
		# so on Pi0w sendNL_IOCTL should be used
		SIOCDEVPRIVATE = 0x89F0
		# create ioctl ifreq
		ifr = nexconf.create_ifreq(device_name, ioc)
		# debug out
		'''
		print repr(nexconf.c_struct2str(ifr))
		print len(nexconf.c_struct2str(ifr))
		print repr(string_at(ifr.ifr_data, sizeof(ioc)))
		'''
		# send ioctl to kernel via UDP socket
		s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
		fcntl.ioctl(s.fileno(), SIOCDEVPRIVATE, ifr)
		s.close() 
开发者ID:RoganDawes,项目名称:P4wnP1_nexmon_additions,代码行数:23,代码来源:mame82_util.py


示例13: activate_network_interface

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def activate_network_interface(iface):
    """Bring up the given network interface.
    @raise OSError: if interface does not exist or permissions are missing
    """
    iface = iface.encode()
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_IP)
    try:
        # Get current interface flags from kernel
        ifreq = struct.pack(
            _STRUCT_IFREQ_LAYOUT_IFADDR_SAFAMILY, iface, socket.AF_INET, b"0" * 14
        )
        ifreq = fcntl.ioctl(sock, _SIOCGIFFLAGS, ifreq)
        if_flags = struct.unpack(_STRUCT_IFREQ_LAYOUT_IFFLAGS, ifreq)[1]
        # Set new flags
        ifreq = struct.pack(
            _STRUCT_IFREQ_LAYOUT_IFFLAGS, iface, if_flags | _IFF_UP, b"0" * 14
        )
        fcntl.ioctl(sock, _SIOCSIFFLAGS, ifreq)
    finally:
        sock.close() 
开发者ID:sosy-lab,项目名称:benchexec,代码行数:24,代码来源:container.py


示例14: get_terminal_size

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def get_terminal_size():
        fallback = (80, 24)
        try:
            from shutil import get_terminal_size
        except ImportError:
            try:
                import termios
                import fcntl
                import struct
                call = fcntl.ioctl(0, termios.TIOCGWINSZ, "\x00"*8)
                height, width = struct.unpack("hhhh", call)[:2]
            except (SystemExit, KeyboardInterrupt):
                raise
            except:
                width = int(os.environ.get('COLUMNS', fallback[0]))
                height = int(os.environ.get('COLUMNS', fallback[1]))
            # Work around above returning width, height = 0, 0 in Emacs
            width = width if width != 0 else fallback[0]
            height = height if height != 0 else fallback[1]
            return width, height
        else:
            return get_terminal_size(fallback) 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:24,代码来源:pdbpp.py


示例15: handleResize

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def handleResize(self, signum, frame):
        h,w=array('h', ioctl(sys.stderr,termios.TIOCGWINSZ,'\0'*8))[:2]
        self.term_width = w 
开发者ID:svviz,项目名称:svviz,代码行数:5,代码来源:multiprocessor.py


示例16: _get_terminal_size_linux

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def _get_terminal_size_linux(self):
        def ioctl_GWINSZ(fd):
            try:
                import fcntl
                import termios
                cr = struct.unpack("hh", fcntl.ioctl(fd, termios.TIOCGWINSZ, "1234"))
                return cr
            except:
                pass
        cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
        if not cr:
            try:
                fd = os.open(os.ctermid(), os.O_RDONLY)
                cr = ioctl_GWINSZ(fd)
                os.close(fd)
            except:
                pass
        if not cr:
            try:
                cr = (os.environ["LINES"], os.environ["COLUMNS"])
            except:
                return None
        return int(cr[1]), int(cr[0]) 
开发者ID:sdispater,项目名称:clikit,代码行数:29,代码来源:terminal.py


示例17: _get_terminal_size

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def _get_terminal_size(fd):
        try:
            res = fcntl.ioctl(fd, termios.TIOCGWINSZ, b"\x00" * 4)
            lines, columns = struct.unpack("hh", res)
        except Exception:
            columns = lines = 0
        return terminal_size(columns, lines) 
开发者ID:kislyuk,项目名称:aegea,代码行数:10,代码来源:shutil_get_terminal_size.py


示例18: _handle_resize

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def _handle_resize(self, signum=None, frame=None):
        """Tries to catch resize signals sent from the terminal."""
        h, w = array('h', ioctl(self.fd, termios.TIOCGWINSZ, '\0' * 8))[:2]
        self.term_width = w 
开发者ID:mbusb,项目名称:multibootusb,代码行数:7,代码来源:progressbar.py


示例19: lin_tun_alloc

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def lin_tun_alloc(self, dev, flags):
		try:
			tun = os.open(Interface.LINUX_CLONEDEV, os.O_RDWR|os.O_NONBLOCK, 0)
			ifr = struct.pack('16sH', dev, flags)
			fcntl.ioctl(tun, self.IOCTL_LINUX_TUNSETIFF, ifr)
		except IOError:
			common.internal_print("Error: Cannot create tunnel. Is {0} in use?".format(dev), -1)
			sys.exit(-1)
		return tun 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:13,代码来源:interface.py


示例20: lin_set_ip_address

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def lin_set_ip_address(self, dev, ip, serverip, netmask):
		sockfd = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		try:
			# set IP
			ifr  = struct.pack('<16sH2s4s8s', dev, socket.AF_INET, "\x00"*2, socket.inet_aton(ip), "\x00"*8)
			fcntl.ioctl(sockfd, self.IOCTL_LINUX_SIOCSIFADDR, ifr)
			# get flags
			ifr = struct.pack('<16sh', dev, 0)
			flags = struct.unpack('<16sh', fcntl.ioctl(sockfd, self.IOCTL_LINUX_SIOCSIFFLAGS, ifr))[1]
			# set new flags
			flags = flags | self.IOCTL_LINUX_IFF_UP
			ifr = struct.pack('<16sh', dev, flags)
			# iface up
			fcntl.ioctl(sockfd, self.IOCTL_LINUX_SIOCSIFFLAGS, ifr)
		except Exception as e:
			common.internal_print("Something went wrong with setting up the interface.", -1)
			print(e)
			sys.exit(-1)
		# adding new route for forwarding packets properly.
		integer_ip = struct.unpack(">I", socket.inet_pton(socket.AF_INET, serverip))[0]
		rangeip = socket.inet_ntop(socket.AF_INET, struct.pack(">I", integer_ip & ((2**int(netmask))-1)<<32-int(netmask)))
		integer_netmask = struct.pack(">I", ((2**int(netmask))-1)<<32-int(netmask))
		netmask = socket.inet_ntoa(integer_netmask)
		ps = subprocess.Popen(["route", "add", "-net", rangeip, "netmask", netmask, "dev", dev], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
		(stdout, stderr) = ps.communicate()
		if stderr:
			if not "File exists" in stderr:
				common.internal_print("Error: adding client route: {0}".format(stderr), -1)
				sys.exit(-1)
		return 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:39,代码来源:interface.py


示例21: lin_set_mtu

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def lin_set_mtu(self, dev, mtu):
		s = socket.socket(type=socket.SOCK_DGRAM)
		try:
			ifr = struct.pack('<16sH', dev, mtu) + '\x00'*14
			fcntl.ioctl(s, self.IOCTL_LINUX_SIOCSIFMTU, ifr)
		except Exception as e:
			common.internal_print("Cannot set MTU ({0}) on interface".format(mtu), -1)
			sys.exit(-1)
		return 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:12,代码来源:interface.py


示例22: freebsd_set_ip_address

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def freebsd_set_ip_address(self, dev, ip, serverip, netmask):
		sockfd = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		try:
			#set ip, serverip and netmask
			ifaliasreq = struct.pack('<16sBBHI8sBBHI8sBBHI8sI', self.iface_name,
				16, socket.AF_INET, 0, struct.unpack('<I', socket.inet_aton(ip))[0], '\x00'*8,
				16, socket.AF_INET, 0, struct.unpack('<I', socket.inet_aton(serverip))[0], '\x00'*8,
				16, socket.AF_INET, 0, struct.unpack('<I', socket.inet_aton('255.255.255.255'))[0],
				'\x00'*8,
				0)
			fcntl.ioctl(sockfd, self.IOCTL_FREEBSD_SIOCAIFADDR, ifaliasreq)
			# get flags
			ifr = struct.pack('<16sh', self.iface_name, 0)
			flags = struct.unpack('<16sh', fcntl.ioctl(sockfd, self.IOCTL_FREEBSD_SIOCGIFFLAGS, ifr))[1]
			# set new flags
			flags = flags | self.IOCTL_FREEBSD_IFF_UP
			ifr = struct.pack('<16sh', self.iface_name, flags)
			# iface up
			fcntl.ioctl(sockfd, self.IOCTL_FREEBSD_SIOCSIFFLAGS, ifr)
		except Exception as e:
			common.internal_print("Something went wrong with setting up the interface.", -1)
			print(e)
			sys.exit(-1)
		# adding new route for forwarding packets properly.
		integer_ip = struct.unpack(">I", socket.inet_pton(socket.AF_INET, serverip))[0]
		rangeip = socket.inet_ntop(socket.AF_INET, struct.pack(">I", integer_ip & ((2**int(netmask))-1)<<32-int(netmask)))
		ps = subprocess.Popen(["route", "add", "-net", rangeip+"/"+netmask, serverip], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
		(stdout, stderr) = ps.communicate()
		if stderr:
			if not "File exists" in stderr:
				common.internal_print("Error: adding client route: {0}".format(stderr), -1)
				sys.exit(-1)
		return 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:41,代码来源:interface.py


示例23: freebsd_set_mtu

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def freebsd_set_mtu(self, dev, mtu):
		s = socket.socket(type=socket.SOCK_DGRAM)
		try:
			ifr = struct.pack('<16sH', self.iface_name, mtu) + '\x00'*14
			fcntl.ioctl(s, self.IOCTL_FREEBSD_SIOCSIFMTU, ifr)
		except Exception as e:
			common.internal_print("Cannot set MTU ({0}) on interface".format(mtu), -1)
			sys.exit(-1)
		return 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:12,代码来源:interface.py


示例24: freebsd_close_tunnel

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def freebsd_close_tunnel(self, tun):
		try:
			os.close(tun)
		except:
			pass
		s = socket.socket(type=socket.SOCK_DGRAM)
		try:
			ifr = struct.pack('<16s', self.iface_name) + '\x00'*16
			fcntl.ioctl(s, self.IOCTL_FREEBSD_SIOCIFDESTROY, ifr)
		except Exception as e:
			common.internal_print("Cannot destroy interface: {0}".format(dev), -1)
		return 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:16,代码来源:interface.py


示例25: __init__

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def __init__(self, video_device, width, height, channels=3, input_pixfmt='RGB'):
        if channels != 3:
            raise NotImplementedError('Code only supports inputs with 3 channels right now. You tried to intialize with {} channels'.format(channels))
        if input_pixfmt != 'RGB':
            raise NotImplementedError('Code only supports RGB pixfmt. You tried to intialize with {}'.format(input_pixfmt))
        if not os.path.exists(video_device):
            sys.stderr.write('\n--- Make sure the v4l2loopback kernel module is loaded ---\n')
            sys.stderr.write('sudo modprobe v4l2loopback devices=1\n\n')
            raise FileNotFoundError('device does not exist: {}'.format(video_device))
        self._channels = channels
        self._video_device = os.open(video_device, os.O_WRONLY | os.O_SYNC)
        self._settings = _v4l2.v4l2_format()
        self._settings.type = _v4l2.V4L2_BUF_TYPE_VIDEO_OUTPUT
        self._settings.fmt.pix.pixelformat = _v4l2.V4L2_PIX_FMT_YUYV
        self._settings.fmt.pix.width = width
        self._settings.fmt.pix.height = height
        self._settings.fmt.pix.field = _v4l2.V4L2_FIELD_NONE
        self._settings.fmt.pix.bytesperline = width * 2
        self._settings.fmt.pix.sizeimage = width * height * 2
        self._settings.fmt.pix.colorspace = _v4l2.V4L2_COLORSPACE_JPEG
        self._buffer = np.zeros((self._settings.fmt.pix.height, 2*self._settings.fmt.pix.width), dtype=np.uint8)
        self._yuv = np.zeros((self._settings.fmt.pix.height, self._settings.fmt.pix.width, 3), dtype=np.uint8)
        self._ones = np.ones((self._settings.fmt.pix.height, self._settings.fmt.pix.width, 1), dtype=np.uint8)
        self._rgb2yuv = np.array([[0.299, 0.587, 0.114, 0],
                                  [-0.168736, -0.331264, 0.5, 128],
                                  [0.5, -0.418688, -0.081312, 128]])
        fcntl.ioctl(self._video_device, _v4l2.VIDIOC_S_FMT, self._settings) 
开发者ID:jremmons,项目名称:pyfakewebcam,代码行数:37,代码来源:pyfakewebcam.py


示例26: print_capabilities

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def print_capabilities(self):
        capability = _v4l2.v4l2_capability()
        print(("get capabilities result", (fcntl.ioctl(self._video_device, _v4l2.VIDIOC_QUERYCAP, capability))))
        print(("capabilities", hex(capability.capabilities)))
        print(("v4l2 driver: {}".format(capability.driver)))
    # TODO: improve the conversion from RGB to YUV using cython when opencv is not available 
开发者ID:jremmons,项目名称:pyfakewebcam,代码行数:11,代码来源:pyfakewebcam.py


示例27: interfaces

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def interfaces(self):
        if self.homebrewNetifaces:
            import array
            import fcntl
            maxInterfaces = 128
            bufsiz = maxInterfaces * 40
            nullByte = b'\0'
            s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            ifNames = array.array('B', nullByte * bufsiz)
            ifNameLen = struct.unpack('iL', fcntl.ioctl(
                s.fileno(),
                0x8912, # SIOCGIFCONF
                struct.pack('iL', bufsiz, ifNames.buffer_info()[0])
            ))[0]
            if ifNameLen % self.ifNameStructLen != 0:
                print('Do you need to set --ifNameStructLen? %s/%s ought to have a remainder of zero.' % (ifNameLen, self.ifNameStructLen))
                sys.exit(1)
            ifNames = ifNames.tostring()
            for i in range(0, ifNameLen, self.ifNameStructLen):
                name      = ifNames[i:i+16].split(nullByte, 1)[0].decode()
                if not name:
                    print('Cannot determine interface name: do you need to set --ifNameStructLen? %s/%s ought to have a remainder of zero.' % (ifNameLen, self.ifNameStructLen))
                    sys.exit(1)
                ip        = socket.inet_ntoa(fcntl.ioctl(socket.socket(socket.AF_INET, socket.SOCK_DGRAM), 0x8915, struct.pack('256s', str(name)))[20:24]) # SIOCGIFADDR
                netmask   = socket.inet_ntoa(fcntl.ioctl(socket.socket(socket.AF_INET, socket.SOCK_DGRAM), 0x891b, struct.pack('256s', str(name)))[20:24]) # SIOCGIFNETMASK
                broadcast = socket.inet_ntoa(fcntl.ioctl(socket.socket(socket.AF_INET, socket.SOCK_DGRAM), 0x8919, struct.pack('256s', str(name)))[20:24]) # SIOCGIFBRDADDR
                hwaddr    = ':'.join(['%02x' % ord(char) for char in fcntl.ioctl(socket.socket(socket.AF_INET, socket.SOCK_DGRAM), 0x8927, struct.pack('256s', str(name)))[18:24]]) # SIOCGIFHWADDR
                self.interfaceAttrs[name] = {Netifaces.AF_LINK: [{'addr': hwaddr}], Netifaces.AF_INET: [{'addr': ip, 'netmask': netmask, 'broadcast': broadcast}]}
            return self.interfaceAttrs.keys()
        else:
            import netifaces
            return netifaces.interfaces() 
开发者ID:alsmith,项目名称:multicast-relay,代码行数:38,代码来源:multicast-relay.py


示例28: get_ip_address

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def get_ip_address(ifname):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', ifname[:15]))[20:24])
#嗅探 
开发者ID:HatBoy,项目名称:SimpleSniffer,代码行数:7,代码来源:Sniffer.py


示例29: __get_vibration_code

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def __get_vibration_code(self, left_motor, right_motor, duration):
        """This is some crazy voodoo, if you can simplify it, please do."""
        inner_event = struct.pack(
            '2h6x2h2x2H28x',
            0x50,
            -1,
            duration,
            0,
            int(left_motor * 65535),
            int(right_motor * 65535))
        buf_conts = ioctl(self._write_device, 1076905344, inner_event)
        return int(codecs.encode(buf_conts[1:3], 'hex'), 16) 
开发者ID:zeth,项目名称:inputs,代码行数:14,代码来源:inputs.py


示例30: get_linux_ip

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import ioctl [as 别名]
def get_linux_ip(eth):
    """在Linux下获取IP"""
    assert os.name == 'posix', NotLinuxSystemError('不是Linux系统')
    import fcntl
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    ip = socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', eth[:15])))
    return ip[20:24] 
开发者ID:jtyoui,项目名称:Jtyoui,代码行数:9,代码来源:gateway.py



注:本文中的fcntl.ioctl方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。