{"id":85,"date":"2008-07-25T23:26:40","date_gmt":"2008-07-26T04:26:40","guid":{"rendered":"http:\/\/blogs.cae.tntech.edu\/mwr\/?p=85"},"modified":"2024-10-27T14:26:19","modified_gmt":"2024-10-27T14:26:19","slug":"wheres-marcopolo-for-windows","status":"publish","type":"post","link":"https:\/\/sites.tntech.edu\/renfro\/2008\/07\/25\/wheres-marcopolo-for-windows\/","title":{"rendered":"Where&#8217;s MarcoPolo for Windows?"},"content":{"rendered":"<p><a href=\"http:\/\/www.symonds.id.au\/marcopolo\/\">MarcoPolo<\/a>, &#8220;context-aware computing for OS X&#8221; appeals to all three great virtues of the programmer: Laziness, Impatience, and Hubris. It makes me want a Mac notebook. Unfortunately, Pro\/E, ANSYS, and other necessary tools for my regular work would mean I&#8217;d end up dual-booting the Mac all the time. And I&#8217;d miss my port replicator and its enabling me to have one connection to the monitor, keyboard, mouse, network, etc.<\/p>\n<p>So, why not build a MarcoPolo for Windows? I&#8217;ve not yet found one, but I&#8217;d be more than happy to be proven wrong there. In the meantime, I&#8217;m working on a Python\/Windows proof-of-concept that could be the groundwork for a Windows analogue to MarcoPolo.<br \/>\n<!--more--><br \/>\n[code language=&#8221;py&#8221;]<br \/>\n# Idea for Win32 version of MarcoPolo (Context-aware computing for Mac OS X)<\/p>\n<p># Contexts<br \/>\ncontexts = {<br \/>\n    &#8216;Home&#8217;: 1,<br \/>\n    &#8216;Work&#8217;: 1,<br \/>\n    &#8216;pre-Noon&#8217;: 1,<br \/>\n    &#8216;post-Noon&#8217;: 1,<br \/>\n    &#8216;Unknown&#8217;: 1,<br \/>\n}<\/p>\n<p>import wmi, pybonjour, time, IP4Range<br \/>\n# wmi: http:\/\/tgolden.sc.sabren.com\/python\/wmi.html<br \/>\n# pybonjour: http:\/\/o2s.csail.mit.edu\/o2s-wiki\/pybonjour<br \/>\n# IP4Range: http:\/\/code.activestate.com\/recipes\/466298\/<\/p>\n<p>def main():<br \/>\n    c=wmi.WMI()<br \/>\n    # Evidence sources via WMI (direct from MarcoPolo features, some<br \/>\n    # sources may not be available in Win32)<\/p>\n<p>    # Current audio output device (headphones\/speakers) &#8212; may not be<br \/>\n    # discoverable on XP and earlier.<\/p>\n<p>    # Discoverable Bluetooth devices &#8212; can find a Bluetooth adapter via<br \/>\n    # USB, but not a connected end-user device<\/p>\n<p>    # Advertised Bonjour (Zeroconf) services &#8212; &#8216;browse_and_resolve.py<br \/>\n    # _daap._tcp&#8217; finds a remote iTunes share, but no idea how to look for<br \/>\n    # random services.<\/p>\n<p>    # Attached FireWire devices &#8212; no FireWire-capable computers on hand<\/p>\n<p>    # Assigned IP addresses<br \/>\n    ipList=[]<br \/>\n    for adapter in c.Win32_NetworkAdapterConfiguration(IPEnabled=&#8221;True&#8221;):<br \/>\n        ipList.append(adapter.IPAddress[0])<\/p>\n<p>    # Ambient light level \u2014 may not be any standard sensors available to<br \/>\n    # Windows<\/p>\n<p>    # Attached monitors<br \/>\n    monitorList=[]<br \/>\n    for monitor in c.Win32_DesktopMonitor(Availability=3):<br \/>\n        monitorList.append(monitor.Name)<\/p>\n<p>    # Active network links<br \/>\n    networkAdapterList=[]<br \/>\n    for adapter in c.Win32_NetworkAdapter(NetConnectionStatus=2):<br \/>\n        networkAdapterList.append(adapter.Description)<\/p>\n<p>    # Power source (power adapter\/battery) \u2014 need to test on laptop<\/p>\n<p>    # Running Applications<br \/>\n    applicationList=[]<br \/>\n    for process in c.Win32_Process():<br \/>\n        applicationList.append(process.Name)<\/p>\n<p>    # Time of day<br \/>\n    timeOfDay=time.strftime(&#8220;%H:%M&#8221;)<\/p>\n<p>    # Attached USB devices<br \/>\n    usbDeviceList=[]<br \/>\n    for device in c.Win32_USBControllerDevice():<br \/>\n        usbDeviceList.append(device.Dependent.Description)<\/p>\n<p>    # Visible WiFi networks \u2014 need to test on laptop<\/p>\n<p>    # Rules (type, criteria, context, confidence)<br \/>\n    ruleList = [<br \/>\n        (&#8216;usb&#8217;, &#8216;Brother HL-5140 series&#8217;, &#8216;Home&#8217;, 0.80),<br \/>\n        (&#8216;usb&#8217;, &#8216;Visioneer OneTouch 7300&#8217;, &#8216;Home&#8217;, 0.99),<br \/>\n        (&#8216;monitor&#8217;, &#8216;Plug and Play Monitor&#8217;, &#8216;Home&#8217;, 0.60),<br \/>\n        (&#8216;ip&#8217;, &#8216;192.168.254.4&#8217;, &#8216;Home&#8217;, 0.50),<br \/>\n        (&#8216;ip&#8217;, &#8216;149.149.254.0\/24&#8217;, &#8216;Work&#8217;, 0.99),<br \/>\n        (&#8216;ssid&#8217;, &#8216;mike-and-carolyn&#8217;, &#8216;Home&#8217;, 0.99),<br \/>\n        (&#8216;time&#8217;, [&#8217;00:00&#8242;, &#8217;11:59&#8242;], &#8216;pre-Noon&#8217;, 0.99),<br \/>\n        (&#8216;time&#8217;, [&#8217;12:00&#8242;, &#8217;23:59&#8242;], &#8216;post-Noon&#8217;, 0.99),<br \/>\n        ]<\/p>\n<p>    # Decision<br \/>\n    for rule in ruleList:<br \/>\n        itemFound = -1<br \/>\n        (ruleType, ruleItem, ruleContext, ruleStrength) = rule<br \/>\n        if ruleType==&#8217;ip&#8217;:<br \/>\n            ipRange=IP4Range.IP4Range(ruleItem)<br \/>\n            for ip in ipList:<br \/>\n                currentIP=IP4Range.IP4Range(ip.encode(&#8216;ascii&#8217;))<br \/>\n                if currentIP.issubset(ipRange):<br \/>\n                    itemFound = 1<\/p>\n<p>        elif ruleType==&#8217;monitor&#8217;:<br \/>\n            try:<br \/>\n                itemFound = monitorList.index(ruleItem)<br \/>\n            except ValueError:<br \/>\n                pass<br \/>\n        elif ruleType==&#8217;adapter&#8217;:<br \/>\n            try:<br \/>\n                itemFound = networkAdapterList.index(ruleItem)<br \/>\n            except ValueError:<br \/>\n                pass<br \/>\n        elif ruleType==&#8217;application&#8217;:<br \/>\n            try:<br \/>\n                itemFound = applicationList.index(ruleItem)<br \/>\n            except ValueError:<br \/>\n                pass<br \/>\n        elif ruleType==&#8217;usb&#8217;:<br \/>\n            try:<br \/>\n                itemFound = usbDeviceList.index(ruleItem)<br \/>\n            except ValueError:<br \/>\n                pass<br \/>\n        elif ruleType==&#8217;time&#8217;:<br \/>\n            if cmp(timeOfDay,ruleItem[0])&gt;=0 and cmp(timeOfDay,ruleItem[1])myConfidence:<br \/>\n                myLocation=context<br \/>\n                myConfidence = 1-contexts[context]<\/p>\n<p>    print &#8220;Your location: %s (confidence %f)&#8221; % (myLocation, myConfidence)<br \/>\n    print<\/p>\n<p>if __name__ == &#8220;__main__&#8221;:<br \/>\n    main()<br \/>\n[\/code]<br \/>\nI know my Python is mediocre at best. But this does work so far in my limited testing (&#8220;Unknown rule type ssid, Your location: Home (confidence 0.999600)&#8221;). Thanks to David Symonds for his assistance in <a href=\"http:\/\/groups.google.com\/group\/marcopolo-discuss\/browse_thread\/thread\/c4c4e7f6521af282\/396bbcff92029b7b\">this thread<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MarcoPolo, &#8220;context-aware computing for OS X&#8221; appeals to all three great virtues of the programmer: Laziness, Impatience, and Hubris. It makes me want a Mac notebook. Unfortunately, Pro\/E, ANSYS, and other necessary tools for my regular work would mean I&#8217;d end up dual-booting the Mac all the time. And I&#8217;d miss my port replicator and &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/sites.tntech.edu\/renfro\/2008\/07\/25\/wheres-marcopolo-for-windows\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Where&#8217;s MarcoPolo for Windows?&#8221;<\/span><\/a><\/p>\n","protected":false},"author":87,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-85","post","type-post","status-publish","format-standard","hentry","category-python","entry"],"_links":{"self":[{"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/posts\/85","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/users\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/comments?post=85"}],"version-history":[{"count":1,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/posts\/85\/revisions"}],"predecessor-version":[{"id":458,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/posts\/85\/revisions\/458"}],"wp:attachment":[{"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/media?parent=85"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/categories?post=85"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sites.tntech.edu\/renfro\/wp-json\/wp\/v2\/tags?post=85"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}