{"id":405,"date":"2014-08-27T19:52:02","date_gmt":"2014-08-27T18:52:02","guid":{"rendered":"http:\/\/www.sebcharrot.com\/blog\/?p=405"},"modified":"2014-08-27T19:52:02","modified_gmt":"2014-08-27T18:52:02","slug":"exposing-a-vm-on-hosted-wifi-hotspot-for-google-glass","status":"publish","type":"post","link":"http:\/\/www.sebcharrot.com\/blog\/exposing-a-vm-on-hosted-wifi-hotspot-for-google-glass\/","title":{"rendered":"Exposing a VM on hosted WiFi hotspot for Google Glass"},"content":{"rendered":"<h2><strong>Background<\/strong><\/h2>\n<p>Google Glass is famously frustrating to connect to a WiFi network. It doesn\u2019t handle <a href=\"http:\/\/en.wikipedia.org\/wiki\/Captive_portal\">captive portals<\/a>, or WiFi using Enterprise WPA2. I\u2019ve also had consistent issues using <a href=\"https:\/\/support.google.com\/glass\/answer\/2725950?hl=en-GB\">MyGlass and QR codes to connect to Wifi<\/a>.<\/p>\n<p>I found myself in a situation where I had to connect Glass to a WiFi\u00a0network on which a virtual machine was visible. My work\u2019s corporate network was out of the question \u2013 it uses Enterprise WPA2. I would have connected my phone to the network and shared it to Glass via Bluetooth, but that was nixed for security reasons. So I had to set up a new network exclusively for Glass.<\/p>\n<p>First thought \u2013 let\u2019s just set up an <a href=\"http:\/\/compnetworking.about.com\/od\/wireless\/ht\/setupadhocwifi.htm\">Ad-Hoc wireless network on my laptop<\/a>! But no, alas Android <a href=\"https:\/\/code.google.com\/p\/android\/issues\/detail?id=82\">doesn\u2019t support connecting to ad-hoc networks<\/a>. Universe, why do you hate me so?<\/p>\n<h2><strong>The solution<\/strong><\/h2>\n<p>The solution involves a wireless-enabled Windows machine and <a href=\"https:\/\/www.virtualbox.org\/\">VirtualBox<\/a>\u00a0&#8211; a program\u00a0for running virtual machines.<\/p>\n<p>An alternative to creating an ad-hoc network on your machine is to create a <a href=\"http:\/\/msdn.microsoft.com\/en-gb\/library\/windows\/desktop\/dd815243(v=vs.85).aspx\">Wireless Hosted Network<\/a>. This basically allows your Windows machine to act as a WiFi hotspot which can pass through a (wired) internet connection if you so wish.<\/p>\n<p>My approach was to create a hosted network, connect my phone to it, then pass on the connection via Bluetooth. An admittedly insane chain of connections, but it\u2019s all\u00a0I had.<\/p>\n<h2><strong>Create the WiFi network<\/strong><\/h2>\n<ol>\n<li>Open the Start menu and type \u201ccmd\u201d<\/li>\n<li>Right click and select \u201cRun as Administrator\u201d<\/li>\n<li>Type the following command:\n<pre> netsh wlan set hostednetwork mode=allow ssid=mynetworkid key=mypassword<\/pre>\n<\/li>\n<\/ol>\n<h2><strong>Start the network<\/strong><\/h2>\n<p>You\u2019ll have to do this every time you start the machine, or alternatively set up a batch script to run this on startup.<\/p>\n<ol>\n<li>Type the following command:\n<pre> netsh wlan start hostednetwork<\/pre>\n<\/li>\n<\/ol>\n<p>You should now see \u201cmynetworkid\u201d (or whatever you called it) in your list of wireless networks.<\/p>\n<h2><strong>Create your VirtualBox image<\/strong><\/h2>\n<ol>\n<li>Install VirtualBox<\/li>\n<li>Create a new virtual machine (steps available <a href=\"http:\/\/docs.oracle.com\/cd\/E26217_01\/E26796\/html\/qs-create-vm.html\">here<\/a>) \u2013 I\u2019ve chosen to use a linux install<\/li>\n<li>Once your VM is created, go to Settings and choose Network<\/li>\n<li>Set up a Bridged Adapter\n<ol>\n<li>Enable a network adapter<\/li>\n<li>Select Attached To: \u201cBridged Adapter\u201d<\/li>\n<li>Select \u201cMicrosoft Virtual WiFi Miniport Adapter\u201d as the Name \u2013 this is where the network you\u2019ve just created is hosted.<\/li>\n<\/ol>\n<\/li>\n<li>Start your VM up<\/li>\n<\/ol>\n<h2><strong>Check connectivity<\/strong><\/h2>\n<ol>\n<li>On your Windows machine, open a command line and type:\n<pre> ipconfig<\/pre>\n<p>A list of networks should be shown \u2013 one of which should be called \u201cWireless LAN adapter Wireless Network Connection\u201d. Note down the first 9 digits of the IP address listed under this e.g. 192.168.173<\/li>\n<li>In your VM, run the following command:\n<pre> \/sbin\/ifconfig<\/pre>\n<p>And note the networks and IPs that are listed. If no other networks were set up, your eth0 network should have an IP where the first 9 digits of the IP address matches those you noted down earlier. That means that they\u2019re running on the network.<\/li>\n<li>For a laugh, ping your VM from your Windows machine, using the IP address from the previous step. This will confirm that your VM is addressable and contactable from your Windows machine. Given that your Windows machine is now broadcasting a wireless network, that means that the VM should be contactable to anyone on the network too.<\/li>\n<\/ol>\n<p><strong>Ping your VM from your Android device<\/strong><\/p>\n<p>As the penultimate proof, try pinging your VM from your Android device.<\/p>\n<ol>\n<li>Install an app which will let you run a ping command (I used <a href=\"https:\/\/play.google.com\/store\/apps\/details?id=ua.com.streamsoft.pingtools&amp;hl=en\">PingTools<\/a>)<\/li>\n<li>Ping the IP address you pinged previously<\/li>\n<\/ol>\n<p>This should also show a response. And now we\u2019re on the home straight.<\/p>\n<p><strong>Write some Glass code to contact your VM<\/strong><\/p>\n<p>You can do this however you wish. I wrote some very simple ping code to prove that Glass \u2013 once paired to my phone \u2013 was sharing the same internet connection as the phone, and the Windows machine, and as the VM.<\/p>\n<p>There are tons of ways of doing it \u2013 for example:<\/p>\n<pre style=\"padding-left: 30px;\">InetAddress server = InetAddress.getByName(\"192.168.173.123\");\nif (server.isReachable(10000))\n{\n         \/\/ It\u2019s contactable!\n         celebrate();\n}<\/pre>\n<p><strong>Conclusions<\/strong><\/p>\n<p>That was much, much harder than it should have been. Alternatives I didn\u2019t attempt:<\/p>\n<ul>\n<li>Buying a router and broadcasting my corportate ethernet through it<\/li>\n<li>Getting a company-approved phone that could have connected to the Enterprise network<\/li>\n<li>Binning my Google Glass<\/li>\n<\/ul>\n<p>PS &#8211; Many thanks to <a href=\"http:\/\/forum.xda-developers.com\/galaxy-s2\/general\/guide-alternate-to-ad-hoc-wi-fi-network-t1924911\">this post<\/a> which acted as a great reference. It\u2019s also worth checking out if you need to pass through internet via your hosted network.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Background Google Glass is famously frustrating to connect to a WiFi network. It doesn\u2019t handle captive portals, or WiFi using Enterprise WPA2. I\u2019ve also had consistent issues using MyGlass and QR codes to connect to Wifi. I found myself in a situation where I had to connect Glass to a WiFi\u00a0network on which a virtual&hellip;&nbsp;<a href=\"http:\/\/www.sebcharrot.com\/blog\/exposing-a-vm-on-hosted-wifi-hotspot-for-google-glass\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Exposing a VM on hosted WiFi hotspot for Google Glass<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":""},"categories":[21,23,15],"tags":[93,105,179,180,181,186],"_links":{"self":[{"href":"http:\/\/www.sebcharrot.com\/blog\/wp-json\/wp\/v2\/posts\/405"}],"collection":[{"href":"http:\/\/www.sebcharrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sebcharrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sebcharrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sebcharrot.com\/blog\/wp-json\/wp\/v2\/comments?post=405"}],"version-history":[{"count":0,"href":"http:\/\/www.sebcharrot.com\/blog\/wp-json\/wp\/v2\/posts\/405\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sebcharrot.com\/blog\/wp-json\/wp\/v2\/media?parent=405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sebcharrot.com\/blog\/wp-json\/wp\/v2\/categories?post=405"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sebcharrot.com\/blog\/wp-json\/wp\/v2\/tags?post=405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}