<div dir="ltr"><div>You can write a startup.py file and put it into the <user>/.qgis2/python folder.</div><div>It will be loaded and executed, so you could check for internet availability with something as simple as:</div>
<div><br></div><div>------------------------------------------------------</div><div>import urllib2</div><div>url = <your_wms_server_getcapabilities_service></div><div>try:</div><div> urllib2.urlopen(url)</div><div>
except urllib2.URLError, e:</div><div> print "Could not connect"</div><div>-----------------------------------------------------</div><div><br></div><div>Last time I needed it I used the following (with various adaptations):</div>
<div><br></div><div>-----------------------------------------------------</div><div>import sys</div><div>import socket</div><div>import time</div><div><br></div><div>host = <my_url></div><div>port = <my_port_number></div>
<div># type => ["tcp" or "udp"]</div><div>type = sys.argv[3]</div><div>test = ""</div><div>if len(sys.argv) > 4 :</div><div> test = sys.argv[4]</div><div><br></div><div>while 1 :</div><div>
if type == "udp":</div><div> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)</div><div> else:</div><div> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)</div><div> s.settimeout(5)</div><div>
try:</div><div> if type == "udp":</div><div> s.sendto("--TEST LINE--", (host, port))</div><div> recv, svr = s.recvfrom(255)</div><div> s.shutdown(2)</div><div> print "Success connecting to " + host + " on UDP port: " + str(port)</div>
<div> else:</div><div> s.connect((host, port))</div><div> s.shutdown(2)</div><div> print "Success connecting to " + host + " on TCP port: " + str(port)</div><div> except Exception, e:</div>
<div> try:</div><div> errno, errtxt = e</div><div> except ValueError:</div><div> print "Cannot connect to " + host + " on port: " + str(port)</div><div> else:</div><div> if errno == 107:</div>
<div> print "Success connecting to " + host + " on UDP port: " + str(port)</div><div> else:</div><div> print "Cannot connect to " + host + " on port: " + str(port)</div>
<div> print e</div><div> if test != "C" :</div><div> sys.exit(0)</div><div><br></div><div> s.close</div><div> time.sleep(1)</div><div>--------------------------------------------------------------</div>
<div><br></div><div>Giovanni</div><div><br></div><div>-- </div><div>Giovanni Allegri</div><div><a href="http://about.me/giovanniallegri">http://about.me/giovanniallegri</a></div><div>Twitter: <a href="https://twitter.com/_giohappy_">https://twitter.com/_giohappy_</a></div>
<div>blog: <a href="http://blog.spaziogis.it">http://blog.spaziogis.it</a></div><div>GEO+ geomatica in Italia <a href="http://bit.ly/GEOplus">http://bit.ly/GEOplus</a></div><div class="gmail_extra"><div dir="ltr"></div>
</div></div>