Exemple #1
0
def host_ipaddr(interface=None):
    if sys.platform == "win32":
        return HostUtil.get_inst().gethostbyname()

    cmd = "/sbin/ifconfig"
    if interface:
        cmd = '%s %s' % (cmd, interface)
    fd = os.popen(cmd)

    this_host = None
    interfaces = {}
    name = None

    for line in fd.readlines():
        match = re.match("(\S+)", line)
        if match: name = match.group(1)
        match = re.search("inet addr:(\S+)", line)
        if match:
            addr = match.group(1)
            if name:
                interfaces[name] = addr

    if interfaces.has_key(interface):
        this_host = interfaces[interface]
    else:
        for name, addr in interfaces.items():
            if re.match("ppp", name):
                this_host = addr
                break
            elif re.match("eth", name):
                this_host = addr

    fd.close()

    return this_host or HostUtil.get_inst().gethostbyname()
Exemple #2
0
def host_ipaddr(interface = None):
	if sys.platform == "win32":
		return HostUtil.get_inst().gethostbyname()

	cmd = "/sbin/ifconfig"
	if interface:
		cmd = '%s %s' % (cmd, interface)
	fd = os.popen(cmd)

	this_host  = None
	interfaces = {}
	name       = None

	for line in fd.readlines():
		match = re.match("(\S+)", line)
		if match: name = match.group(1)
		match = re.search("inet addr:(\S+)", line)
		if match:
			addr = match.group(1)
			if name:
				interfaces[name] = addr

	if interfaces.has_key(interface):
		this_host = interfaces[interface]
	else:
		for name, addr in interfaces.items():
			if re.match("ppp", name):
				this_host = addr
				break
			elif re.match("eth", name):
				this_host = addr

	fd.close()

	return this_host or HostUtil.get_inst().gethostbyname()
Exemple #3
0
def getHostname(ip=None):
	try:
		if ip:
			hn,alias, ips = HostUtil.get_inst().gethostbyaddr(ip)
			return hn
		else:
			return HostUtil.get_inst().gethostname()
	except socket.error:
		return None
Exemple #4
0
	def __init__(self, port, host='', threaded=_has_threading,prtcol='PYRO'):
		self._ssl_server = 0
		self.connections = []  # connection threads
		self.initTLS=lambda tls: None  # default do-nothing func
		if host:
			HostUtil.get_inst().gethostbyname(host)  # validate hostname
		try:
			if prtcol=='PYROSSL':
				try:
					from M2Crypto import SSL
				except ImportError:
					raise ProtocolError('SSL not available')
				try:
					self.ctx = SSL.Context('sslv23')
					if Pyro.config.PYROSSL_KEY:
						keyfile = os.path.join(Pyro.config.PYROSSL_CERTDIR, Pyro.config.PYROSSL_KEY)
					else:
						keyfile = None
					self.ctx.load_cert(os.path.join(Pyro.config.PYROSSL_CERTDIR, Pyro.config.PYROSSL_CERT),
							   keyfile)
					self.ctx.load_client_ca(os.path.join(Pyro.config.PYROSSL_CERTDIR, Pyro.config.PYROSSL_CA_CERT))
					self.ctx.load_verify_info(os.path.join(Pyro.config.PYROSSL_CERTDIR, Pyro.config.PYROSSL_CA_CERT))
					self.ctx.set_verify(SSL.verify_peer | SSL.verify_fail_if_no_peer_cert,10)
					self.ctx.set_allow_unknown_ca(1)
					self._ssl_server = 1
					Log.msg('TCPServer','SSL Context initialized')
				except:
					Log.warn('TCPServer','SSL Context could not be initialized !!!')
				self.setNewConnectionValidator(BasicSSLValidator())
			else:
				self.setNewConnectionValidator(DefaultConnValidator())
				
			# create server socket for new connections
			self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
			set_reuse_addr(self.sock)
			set_sock_no_inherit(self.sock)
			self.sock.bind((host,port))
			self.sock.listen(Pyro.config.PYRO_TCP_LISTEN_BACKLOG)
			if self._ssl_server:
				self.sock = SSL.Connection(self.ctx,self.sock)   # wrap server socket as SSL socket
			# rest of members
			self.threaded = threaded
			self.mustShutdown=0  # global shutdown
			self.localStorage=LocalStorage()  # TLS for systems that don't have threads
			return		
		except socket.error,msg:
			raise ProtocolError(msg)
Exemple #5
0
 def _setNSData(self):
    """
    Updates the display of current Name Server information.
    """
    try:
       ns_name, t, ns_ip = HostUtil.get_inst().gethostbyaddr(self.nsHost)
       ns_ip = ns_ip[0]
    except:
       ns_name, ns_ip = self.nsHost, ''
    self.txtCtrlNSHost.SetValue('%s' % ns_name)
    self.txtCtrlNSPort.SetValue('%s' % self.nsPort)
    self.SetTitle('Pyro Name Server ( %s - %s )' % (ns_name, ns_ip))
Exemple #6
0
def find_nameserver(hostname = None, portnum = None):
	if hostname and hostname.find('://') > 0:
		URI = Pyro.core.PyroURI(hostname)
		ns  = Pyro.naming.NameServerProxy(URI)
	else:
		try:
			if verbose:
				print 'Searching for Naming Service on %s:%d...' % \
					(hostname or 'BROADCAST',
					 portnum or Pyro.config.PYRO_NS_BC_PORT)
			locator = Pyro.naming.NameServerLocator()
			ns = locator.getNS(host = hostname, port = portnum)

		except (Pyro.core.PyroError, socket.error), x:
			localhost = HostUtil.get_inst().gethostbyname('localhost')
			if verbose:
				print "Error:", x
				print """
Naming Service not found with broadcast.
Trying local host""", localhost, '...',

			ns = locator.getNS(host = localhost, port = portnum)
Exemple #7
0
def find_nameserver(hostname=None, portnum=None):
    if hostname and hostname.find('://') > 0:
        URI = Pyro.core.PyroURI(hostname)
        ns = Pyro.naming.NameServerProxy(URI)
    else:
        try:
            if verbose:
                print 'Searching for Naming Service on %s:%d...' % \
                 (hostname or 'BROADCAST',
                  portnum or Pyro.config.PYRO_NS_BC_PORT)
            locator = Pyro.naming.NameServerLocator()
            ns = locator.getNS(host=hostname, port=portnum)

        except (Pyro.core.PyroError, socket.error), x:
            localhost = HostUtil.get_inst().gethostbyname('localhost')
            if verbose:
                print "Error:", x
                print """
Naming Service not found with broadcast.
Trying local host""", localhost, '...',

            ns = locator.getNS(host=localhost, port=portnum)
Exemple #8
0
def getIPAddress(host=None):
	try:
		return HostUtil.get_inst().gethostbyname(host or getHostname())
	except socket.error:
		return None