Skip to content

Instantly share code, notes, and snippets.

@oprypin
Last active March 24, 2020 14:32
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oprypin/8ce7c02e38f430b75b7e to your computer and use it in GitHub Desktop.
Save oprypin/8ce7c02e38f430b75b7e to your computer and use it in GitHub Desktop.
Open links in the host OS when clicking them in the guest OS (VirtualBox)

The MIT License (MIT)

Copyright (C) 2015 Oleh Prypin blaxpirit@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#!/usr/bin/env python
import webbrowser
try:
from urllib.parse import parse_qs
except ImportError:
from urlparse import parse_qs
def application(environ, start_response):
try:
if environ['REQUEST_METHOD'] == 'POST':
try:
length = int(environ['CONTENT_LENGTH'])
except KeyError:
length = None
post = parse_qs(environ['wsgi.input'].read(length).decode('utf-8'))
[url] = post['url']
webbrowser.open(url, new=2, autoraise=True)
except Exception as e:
print(repr(e))
start_response('200 OK', [('Content-Type', 'text/html; charset=utf-8')])
return []
if __name__ == '__main__':
from wsgiref.simple_server import make_server
httpd = make_server('127.0.0.1', 1337, application)
httpd.serve_forever()
#!/usr/bin/env python
import webbrowser
from flask import Flask, request
app = Flask(__name__)
@app.route('/', methods=['POST'])
def index():
url = request.values['url']
webbrowser.open(url, new=2, autoraise=True)
return ''
if __name__ == '__main__':
app.run(port=1337)
#!/usr/bin/env python
import sys
try:
from urllib.parse import urlencode
from urllib.request import Request, urlopen
except ImportError:
from urllib import urlencode
from urllib2 import Request, urlopen
url = 'http://10.0.2.2:1337/'
values = {'url': sys.argv[1]}
data = urlencode(values)
if not isinstance(data, bytes):
data = data.encode('utf-8')
req = Request(url, data)
urlopen(req)
#!/bin/sh
curl --data-urlencode "url=$1" http://10.0.2.2:1337/ || chromium "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment