Beispiel #1
0
def main( base_name='coolserver.local.', stype="_http._tcp.local."):
    # http://serverfault.com/questions/78048/whats-the-difference-between-ip-address-0-0-0-0-and-127-0-0-1
    z = Zeroconf( "0.0.0.0" ) # 0.0.0.0 represents all IP addresses on the local machine
    try:
        name = '%s.%s'%( base_name.split('.')[0], stype )
        s = ServiceInfo(
            stype,
            name,
            server = base_name,
            address = socket.inet_aton('127.0.0.1'),
            port = 8080,
            properties = {"hello":"world", "dept":"deustotech"}, # Setting DNS TXT records...
        )
        
        z.registerService( s )
        name = z.probeName( base_name )
        z.unregisterService( s )
        print 'Negotiated name:', name
        s.server = name 
        z.checkService( s )
        z.registerService( s )
        raw_input( 'Press <enter> to release name > ' )
    finally:
        z.close()
Beispiel #2
0
if __name__ == "__main__":
	z = Zeroconf("0.0.0.0")

	base_name = 'ns.local.'
	my_ip = localint.getLocalIP('www.google.fr')
	stype = '_dns._udp.local.'
	login = '******'
	password = '******'
	
	# registering DNS service and nameprobe on mDNS group
	try:
		full_name = '%s.%s'%( base_name.split('.')[0], stype )
		s = ServiceInfo(
			stype,
			full_name, # FQDN mDNS name of server
			server = base_name, # simplified servername (xx1.local.)
			address = socket.inet_aton(my_ip),
			port = 53,
			properties = {"hello":"world", "dept":"ricm"}, # Setting DNS TXT records...
		)
		z.registerService( s )
		serv_name = z.probeName( base_name )
		z.unregisterService( s )
		print 'Negotiated name:', serv_name
		s.server = serv_name	
		z.checkService( s )
		z.registerService( s )
	except:
		print("Error in name registration")

	#update DNS via REST
	url = 'https://'+login+':'+password+'@'+'127.0.0.1'+':5000/hosts'
Beispiel #3
0
    except Exception as err:
        print ("Error in search for DNS server on the network")
        sys.exit(0)
    finally:
        print ("DNS server found....")
        zc.close()

        # register client service and nameprobe on mDNS
    try:
        zc = Zeroconf("0.0.0.0")
        full_name = "%s.%s" % (base_name.split(".")[0], client_type)
        print (full_name)
        s = ServiceInfo(
            client_type,
            full_name,  # FQDN mDNS name of server
            server=base_name,
            address=socket.inet_aton(client_ip),
            port=client_port,
            properties={"hello": "world", "dept": "ricm"},  # Setting DNS TXT records...
        )
        # we register/unregister twice to prevent name conflits by numbering client_name
        zc.registerService(s)
        client_name = zc.probeName(base_name)
        print (client_name)
        zc.unregisterService(s)
        print "Negotiated name:", client_name
        s.server = client_name
        zc.checkService(s)
        zc.registerService(s)
    except:
        print ("Error in name registration")
        zc.close()