예제 #1
0
def main(ip=None):
    print "Multicast DNS Service Discovery for Python, version", __version__
    # It MUST be 0.0.0.0. NOT the local IP address or 127.0.0.1.
    # Otherwise, at least in GNU/Linux, it doesn't get the service
    # info of services registered in other processes (e.g. "coolserver")
    r = Zeroconf( "0.0.0.0" ) 
    #host_ip = socket.gethostbyname( socket.gethostname())
    host_ip = get_ip_address()
    try:
        
        print "1. Testing query of own service..."
        my_service = r.getServiceInfo("_test._tcp.local.", "AndroidTest._test._tcp.local.")
        print "   Getting self:", str(my_service)
        print "   Query done."
        
        raw_input( 'Press <enter> to release name > ' )

    finally:
        r.close()
예제 #2
0
def main(ip=None):
    print "Multicast DNS Service Discovery for Python, version", __version__
    # It MUST be 0.0.0.0. NOT the local IP address or 127.0.0.1.
    # Otherwise, at least in GNU/Linux, it doesn't get the service
    # info of services registered in other processes (e.g. "coolserver")
    r = Zeroconf("0.0.0.0")
    host_ip = socket.gethostbyname(socket.gethostname())
    try:
        print "1. Testing registration of a service..."
        desc = {'version': '0.10', 'a': 'test value', 'b': 'another value'}
        info = ServiceInfo("_http._tcp.local.",
                           "My Service Name._http._tcp.local.",
                           socket.inet_aton(host_ip), 1234, 0, 0, desc)
        print "   Registering service..."
        r.registerService(info)
        print "   Registration done."

        print "2. Testing query of service information..."
        service_info = r.getServiceInfo("_http._tcp.local.",
                                        "coolserver._http._tcp.local.")
        print "   Getting 'coolserver' service: %r" % service_info
        if service_info is None:
            print "       (Did you expect to see here the details of the 'coolserver' service? Try running 'nameprobe.py' before!)"
        print "   Query done."

        print "3. Testing query of own service..."
        my_service = r.getServiceInfo("_http._tcp.local.",
                                      "My Service Name._http._tcp.local.")
        print "   Getting self:", str(my_service)
        print "   Query done."

        raw_input('Press <enter> to release name > ')

        print "4. Testing unregister of service information..."
        r.unregisterService(info)
        print "   Unregister done."
    finally:
        r.close()
예제 #3
0
def main(ip=None):
    print "Multicast DNS Service Discovery for Python, version", __version__
    # It MUST be 0.0.0.0. NOT the local IP address or 127.0.0.1.
    # Otherwise, at least in GNU/Linux, it doesn't get the service
    # info of services registered in other processes (e.g. "coolserver")
    r = Zeroconf( "0.0.0.0" ) 
    host_ip = socket.gethostbyname( socket.gethostname())
    try:
        print "1. Testing registration of a service..."
        desc = {'version':'0.10','a':'test value', 'b':'another value'}
        info = ServiceInfo(
            "_http._tcp.local.", "My Service Name._http._tcp.local.",
            socket.inet_aton(host_ip), 1234, 0, 0, desc
        )
        print "   Registering service..."
        r.registerService(info)
        print "   Registration done."
        
        print "2. Testing query of service information..."
        service_info = r.getServiceInfo("_http._tcp.local.", "coolserver._http._tcp.local.")
        print "   Getting 'coolserver' service: %r" % service_info
        if service_info is None:
	  print "       (Did you expect to see here the details of the 'coolserver' service? Try running 'nameprobe.py' before!)"
        print "   Query done."
        
        print "3. Testing query of own service..."
        my_service = r.getServiceInfo("_http._tcp.local.", "My Service Name._http._tcp.local.")
        print "   Getting self:", str(my_service)
        print "   Query done."
        
        raw_input( 'Press <enter> to release name > ' )
        
        print "4. Testing unregister of service information..."
        r.unregisterService(info)
        print "   Unregister done."
    finally:
        r.close()
예제 #4
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()
예제 #5
0
			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'
	try:
		print('REST update.. ')
		post_name = serv_name.split('.')[0]
		putdata = {'ip': my_ip , 'hostname' : post_name , 'rectype' :'A'}
		httprequests.httpPost(url, putdata)
	except:
		print('Error on REST update.')
		z.close()

	finally :
		raw_input( 'Press <enter> to release name > ' )
		httprequests.httpDelete(url+'/'+post_name)
		z.close()


예제 #6
0
            if not info:
                print "  (timeout)"
            retries += 1
        print "Address is", str(socket.inet_ntoa(info.getAddress()))
        print "Port is", info.getPort()
        print "Weight is", info.getWeight()
        print "Priority is", info.getPriority()
        print "Server is", info.getServer()
        print "Text is", repr(info.getText())
        print "Properties are", info.getProperties()

if __name__ == '__main__':
    import logging, sys
    logging.basicConfig(level=logging.WARNING)
    print "Multicast DNS Service Discovery for Python Browser test"
    if sys.argv[1:]:
        type_ = sys.argv[1]
    else:
        type_ = "_http._tcp.local."
    r = Zeroconf()
    try:
        print "1. Testing browsing for a service (ctrl-c to stop)..."
        try:
            listener = MyListener()
            browser = ServiceBrowser(r, type_, listener)
            raw_input( 'Press <enter> to exit' )
        except KeyboardInterrupt, err:
            print 'Exiting'
    finally:
        r.close()
예제 #7
0
                print "  (timeout)"
            retries += 1
        print "Address is", str(socket.inet_ntoa(info.getAddress()))
        print "Port is", info.getPort()
        print "Weight is", info.getWeight()
        print "Priority is", info.getPriority()
        print "Server is", info.getServer()
        print "Text is", repr(info.getText())
        print "Properties are", info.getProperties()


if __name__ == '__main__':
    import logging, sys
    logging.basicConfig(level=logging.WARNING)
    print "Multicast DNS Service Discovery for Python Browser test"
    if sys.argv[1:]:
        type_ = sys.argv[1]
    else:
        type_ = "_http._tcp.local."
    r = Zeroconf()
    try:
        print "1. Testing browsing for a service (ctrl-c to stop)..."
        try:
            listener = MyListener()
            browser = ServiceBrowser(r, type_, listener)
            raw_input('Press <enter> to exit')
        except KeyboardInterrupt, err:
            print 'Exiting'
    finally:
        r.close()
예제 #8
0
        browser = ServiceBrowser(zc, find_type, listener)
        serv_ip = listener.getServAddress()
        test = 0
        while not serv_ip and test < 5:
            time.sleep(1)
            serv_ip = listener.getServAddress()
            test += test
        print ("Local IP of DNS server  : " + serv_ip)
        # update nameserver
        addNameserver("/run/resolvconf/resolv.conf", serv_ip, "testopendyn.com")
    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