I am connecting to virtual machine with putty ssh from my local machine and running a python script on virtual machine. From the script, I want to open a web browser with specific URL on my local machine. Is it possible to do so with python?
SimpleHTTPServer
is running on virtual machine, and HTML
file is present on it, so I can open URL on virtual machine with localhost:8080
and for local machine, I can use hostname of virtual machine <hostname>:8080.
If I have to open the web browser on virtual machine, I can use following:
import webbrowser
url = "http://localhost:8080/"
webbrowser.open_new(url)
But if I want to open the same URL using hostname of virtual machine on local web browser, not sure what can be used:
import os
hostname = os.uname()[1]
url = "http://%s:8080/" % hostname # this hostname is virtual machine's hostname
print "Opening this URL in your browser: %s" % url
# Here I have to open a web browser manually and copy the URL.
# Looking for something which can open web browser automatically.