Beispiel #1
0
def get_router_config():
    hp = localUPnP(False, False, None, {})
    hp.UNIQ = True
    hp.VERBOSE = False
    hp.TIMEOUT = 1

    #find all devices on the network
    msearch(0, None, hp)

    #get the info from the router and check if its one we are looking for
    #most of this section ripped from the host get command in miranda
    for k, h in hp.ENUM_HOSTS.items():
        print(
            "Requesting device and service info for %s (this could take a few seconds)..."
            % (h['name']))

        (xmlHeaders, xmlData) = hp.getXML(h['xmlFile'])
        if xmlData == False:
            print('Failed to request host XML file:', h['xmlFile'])
            return
        if hp.getHostInfo(xmlData, xmlHeaders, k) == False:
            print("Failed to get device/service info for %s..." % h['name'])
            return
        print(
            'Host data enumeration complete! Checking for GetConfiguration action...'
        )

        #check for the GetConfiguration method
        try:
            if 'GetConfiguration' in h['deviceList']['InternetGatewayDevice'][
                    'services']['DeviceConfig']['actions'].keys():
                #You ripper. Get the config.
                #most of this ripped from miranda send command
                print('...Got it! Grabbing the config.')
                c1 = h['proto'] + h['name']
                c2 = h['deviceList']['InternetGatewayDevice']['services'][
                    'DeviceConfig']['controlURL']
                if not c1.endswith('/') and not c2.startswith('/'):
                    c1 += '/'
                controlURL = c1 + c2
                fullServiceName = h['deviceList']['InternetGatewayDevice'][
                    'services']['DeviceConfig']['fullName']

                #send the request
                sr = hp.sendSOAP(h['name'], fullServiceName, controlURL,
                                 'GetConfiguration', {})
                if sr != False:
                    tv = hp.extractSingleTag(sr, 'NewConfigFile')
                    return tv

        except KeyError:
            pass
Beispiel #2
0
def search():
	conn.TIMEOUT = 2
	conn.UNIQ = True
	msearch(0, 0, conn)

	wemos = []
	for index, hostInfo in conn.ENUM_HOSTS.iteritems():
		if hostInfo['dataComplete'] == False:
			xmlHeaders, xmlData = conn.getXML(hostInfo['xmlFile'])
			conn.getHostInfo(xmlData, xmlHeaders, index)
		try:
			if conn.ENUM_HOSTS[index]['deviceList']['controllee']['modelName'] == 'Socket':
				wemos.append(WeMo(hostInfo))
		except Exception, e:
			pass
def get_router_config():
    hp = localUPnP(False, False, None, {})
    hp.UNIQ = True
    hp.VERBOSE = False
    hp.TIMEOUT = 1

    #find all devices on the network
    msearch(0, None, hp)

    #get the info from the router and check if its one we are looking for
    #most of this section ripped from the host get command in miranda
    for k,h in hp.ENUM_HOSTS.items():
        print("Requesting device and service info for %s (this could take a few seconds)..." % (h['name']))

        (xmlHeaders,xmlData) = hp.getXML(h['xmlFile'])
        if xmlData == False:
            print('Failed to request host XML file:',h['xmlFile'])
            return
        if hp.getHostInfo(xmlData,xmlHeaders,k) == False:
            print("Failed to get device/service info for %s..." % h['name'])
            return
        print('Host data enumeration complete! Checking for GetConfiguration action...')

        #check for the GetConfiguration method
        try:
            if 'GetConfiguration' in h['deviceList']['InternetGatewayDevice']['services']['DeviceConfig']['actions'].keys():
                #You ripper. Get the config.
                #most of this ripped from miranda send command
                print('...Got it! Grabbing the config.')
                c1 = h['proto'] + h['name']
                c2 = h['deviceList']['InternetGatewayDevice']['services']['DeviceConfig']['controlURL']
                if not c1.endswith('/') and not c2.startswith('/'):
                    c1 += '/'
                controlURL = c1 + c2
                fullServiceName = h['deviceList']['InternetGatewayDevice']['services']['DeviceConfig']['fullName']

                #send the request
                sr = hp.sendSOAP(h['name'],fullServiceName,controlURL,'GetConfiguration',{})
                if sr != False:
                    tv = hp.extractSingleTag(sr,'NewConfigFile')
                    return tv

        except KeyError:
            pass
Beispiel #4
0
def discover(uuid=None):
    conn = upnp()
    if uuid == None:
        msearch(0,0,conn,showUniq=True)
    else:
        msearch(3,['msearch','uuid',uuid],conn,showUniq=True)
        
    # populate all the host info, for every upnp device on the network    
    for index in conn.ENUM_HOSTS:
        hostInfo = conn.ENUM_HOSTS[index]
        if hostInfo['dataComplete'] == False:
            xmlHeaders, xmlData = conn.getXML(hostInfo['xmlFile'])
            conn.getHostInfo(xmlData,xmlHeaders,index)

    for i in conn.ENUM_HOSTS:
        for j in conn.ENUM_HOSTS[i]['deviceList']:
            try:
                print "\n[%d]\ndeviceList: %s\nUDN: %s\nfrendlyName: %s" % (i,j,conn.ENUM_HOSTS[i]['deviceList'][j]['UDN'], conn.ENUM_HOSTS[i]['deviceList'][j]['friendlyName'])
            except:
                print "\n[%d]\ndeviceList: %s\nUDN: %s\nfrendlyName: UNKNOWN" % (i,j,conn.ENUM_HOSTS[i]['deviceList'][j]['UDN'])
    print
    return conn
Beispiel #5
0
from miranda import upnp, msearch
import shelve

conn = upnp()

a = shelve.open("/home/synic/Projects/alexemo/shelve.db")
if not 'HOSTS' in a:
    msearch(0, 0, conn, 4)
    a['HOSTS'] = conn.ENUM_HOSTS

HOSTS = a['HOSTS']
conn.ENUM_HOSTS = HOSTS
a.close()

SWITCHES = []

# populate all the host info, for every upnp device on the network
for index in HOSTS:

    hostInfo = HOSTS[index]
    if hostInfo['dataComplete'] == False:
        xmlHeaders, xmlData = conn.getXML(hostInfo['xmlFile'])
        conn.getHostInfo(xmlData, xmlHeaders, index)

for index in HOSTS:
    try:
        if HOSTS[index]['deviceList']['controllee']['modelName'] == 'Socket':
            SWITCHES = [index]
    except KeyError:
        pass
Beispiel #6
0
				# timeout
				timeout = int(arg)
			elif opt in ("-h"):
				# help
				showusage()
				sys.exit(0)

	# Create the connection
	hp = upnp(False, False, interface, None)

	# Update some of the connection settings
	hp.MAX_HOSTS = 1
	hp.TIMEOUT = timeout

	# Scan for the specified uuid
	msearch(3, ["msearch", "uuid", "Socket-1_0-%s" % serialNumber], hp)

	# Check to make sure that msearch found a device
	if len(hp.ENUM_HOSTS) == 0:
		# Device not found, die gracefully
		print "wemo: device_not_found"
		sys.exit(1)

	# Get the device's details
	hostInfo = hp.ENUM_HOSTS[0]
	if hostInfo['dataComplete'] == False:
		xmlHeaders, xmlData = hp.getXML(hostInfo['xmlFile'])
		hp.getHostInfo(xmlData,xmlHeaders,0)

	# Process command
	if command == "status":
Beispiel #7
0
from miranda import upnp, msearch

conn = upnp(False, False, None, [])
conn.TIMEOUT = 10  # wait for 10 seconds
msearch(0, 0, conn)

SWITCHES = []

# populate all the host info, for every upnp device on the network
for index in conn.ENUM_HOSTS:
    hostInfo = conn.ENUM_HOSTS[index]
    if hostInfo['dataComplete'] == False:
        xmlHeaders, xmlData = conn.getXML(hostInfo['xmlFile'])
        conn.getHostInfo(xmlData,xmlHeaders,index)


for index in conn.ENUM_HOSTS:
    try:
        if conn.ENUM_HOSTS[index]['deviceList']['controllee']['modelName'] == 'Socket':
            SWITCHES = [index]
    except KeyError:
        pass


def _send(action, args=None):
    if not args:
        args = {}
    host_info = conn.ENUM_HOSTS[SWITCHES[0]]
    device_name = 'controllee'
    service_name = 'basicevent'
    controlURL = host_info['proto'] + host_info['name']
Beispiel #8
0
from miranda import upnp, msearch

conn = upnp()
msearch(0, 0, conn, 2)

SWITCHES = []

# populate all the host info, for every upnp device on the network
for index in conn.ENUM_HOSTS:
    hostInfo = conn.ENUM_HOSTS[index]
    if hostInfo['dataComplete'] == False:
        xmlHeaders, xmlData = conn.getXML(hostInfo['xmlFile'])
        conn.getHostInfo(xmlData,xmlHeaders,index)


for index in conn.ENUM_HOSTS:
    try:
        if conn.ENUM_HOSTS[index]['deviceList']['controllee']['modelName'] == 'Socket':
            SWITCHES = [index]
    except KeyError:
        pass


def _send(action, args=None):
    if not args:
        args = {}
    host_info = conn.ENUM_HOSTS[SWITCHES[0]]
    device_name = 'controllee'
    service_name = 'basicevent'
    controlURL = host_info['proto'] + host_info['name']
    controlURL2 = hostInfo['deviceList'][device_name]['services'][service_name]['controlURL']
Beispiel #9
0
from miranda import upnp, msearch

conn = upnp()
msearch(0, 0, conn, 3)

SWITCHES = []

# populate all the host info, for every upnp device on the network
for index in conn.ENUM_HOSTS:
    hostInfo = conn.ENUM_HOSTS[index]
    if hostInfo['dataComplete'] == False:
        xmlHeaders, xmlData = conn.getXML(hostInfo['xmlFile'])
        conn.getHostInfo(xmlData,xmlHeaders,index)


for index in conn.ENUM_HOSTS:
    try:
        if conn.ENUM_HOSTS[index]['deviceList']['controllee']['modelName'] == 'Socket':
            SWITCHES = [index]
    except KeyError:
        pass


def _send(action, args=None):
    if not args:
        args = {}
    host_info = conn.ENUM_HOSTS[SWITCHES[0]]
    device_name = 'controllee'
    service_name = 'basicevent'
    controlURL = host_info['proto'] + host_info['name']
    controlURL2 = hostInfo['deviceList'][device_name]['services'][service_name]['controlURL']
Beispiel #10
0
from miranda import upnp, msearch

conn = upnp()
msearch(0, 0, conn, 2)

SWITCHES = []

# populate all the host info, for every upnp device on the network
for index in conn.ENUM_HOSTS:
    hostInfo = conn.ENUM_HOSTS[index]
    if hostInfo['dataComplete'] == False:
        xmlHeaders, xmlData = conn.getXML(hostInfo['xmlFile'])
        conn.getHostInfo(xmlData, xmlHeaders, index)

for index in conn.ENUM_HOSTS:
    try:
        if conn.ENUM_HOSTS[index]['deviceList']['controllee'][
                'modelName'] == 'Socket':
            SWITCHES = [index]
    except KeyError:
        pass


def _send(action, args=None):
    if not args:
        args = {}
    host_info = conn.ENUM_HOSTS[SWITCHES[0]]
    device_name = 'controllee'
    service_name = 'basicevent'
    controlURL = host_info['proto'] + host_info['name']
    controlURL2 = hostInfo['deviceList'][device_name]['services'][
Beispiel #11
0
from miranda import upnp, msearch

conn = upnp(False, False, None, [])
conn.TIMEOUT = 10  # wait for 10 seconds
msearch(0, 0, conn)

SWITCHES = []

# populate all the host info, for every upnp device on the network
for index in conn.ENUM_HOSTS:
    hostInfo = conn.ENUM_HOSTS[index]
    if hostInfo['dataComplete'] == False:
        xmlHeaders, xmlData = conn.getXML(hostInfo['xmlFile'])
        conn.getHostInfo(xmlData, xmlHeaders, index)

for index in conn.ENUM_HOSTS:
    try:
        if conn.ENUM_HOSTS[index]['deviceList']['controllee'][
                'modelName'] == 'Socket':
            SWITCHES = [index]
    except KeyError:
        pass


def _send(action, args=None):
    if not args:
        args = {}
    host_info = conn.ENUM_HOSTS[SWITCHES[0]]
    device_name = 'controllee'
    service_name = 'basicevent'
    controlURL = host_info['proto'] + host_info['name']
Beispiel #12
0
from miranda import upnp, msearch

conn = upnp(False, False, None, [])
conn.TIMEOUT = 2  # wait for 2 seconds
msearch(4, [0, 'Belkin', 'service', 'basicevent'], conn)
#msearch(4, [0, 'Belkin', 'device', 'controllee'], conn)

SWITCHES = []

# populate all the host info, for every uPNP device on the network
for index in conn.ENUM_HOSTS:
    hostInfo = conn.ENUM_HOSTS[index]
    if hostInfo['dataComplete'] == False:
        xmlHeaders, xmlData = conn.getXML(hostInfo['xmlFile'])
        conn.getHostInfo(xmlData,xmlHeaders,index)


for index in conn.ENUM_HOSTS:
    try:
        if conn.ENUM_HOSTS[index]['deviceList']['controllee']['modelName'] == 'Socket':
            SWITCHES = [index]
    except KeyError:
        pass


def _send(action, args=None):
    if not args:
        args = {}
    host_info = conn.ENUM_HOSTS[SWITCHES[0]]
    device_name = 'controllee'
    service_name = 'basicevent'
Beispiel #13
0
from miranda import upnp, msearch
import shelve

conn = upnp()

a = shelve.open("/home/synic/Projects/alexemo/shelve.db")
if not 'HOSTS' in a:
    msearch(0, 0, conn, 4)
    a['HOSTS'] = conn.ENUM_HOSTS

HOSTS = a['HOSTS']
conn.ENUM_HOSTS = HOSTS
a.close()

SWITCHES = []

# populate all the host info, for every upnp device on the network
for index in HOSTS:
    
    hostInfo = HOSTS[index]
    if hostInfo['dataComplete'] == False:
        xmlHeaders, xmlData = conn.getXML(hostInfo['xmlFile'])
        conn.getHostInfo(xmlData,xmlHeaders,index)


for index in HOSTS:
    try:
        if HOSTS[index]['deviceList']['controllee']['modelName'] == 'Socket':
            SWITCHES = [index]
    except KeyError:
        pass