2017-05-30 10:33:53 +02:00
|
|
|
"""Displays public IP address
|
|
|
|
|
2017-06-05 09:30:23 +02:00
|
|
|
Requires the following python packages:
|
|
|
|
* requests
|
|
|
|
|
|
|
|
Parameters:
|
2017-10-13 17:09:09 +02:00
|
|
|
* publicip.region: us-central (default), us-east, us-west, uk, de, pl, nl
|
2017-06-05 09:53:44 +02:00
|
|
|
* publicip.service: web address that returns plaintext ip address (ex. "http://l2.io/ip")
|
2017-05-30 10:33:53 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
try:
|
2017-06-05 09:30:23 +02:00
|
|
|
from requests import get
|
2017-05-30 10:33:53 +02:00
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
import bumblebee.output
|
|
|
|
import bumblebee.engine
|
|
|
|
|
|
|
|
class Module(bumblebee.engine.Module):
|
|
|
|
def __init__(self, engine, config):
|
|
|
|
super(Module, self).__init__(engine, config,
|
|
|
|
bumblebee.output.Widget(full_text=self.public_ip)
|
|
|
|
)
|
2017-10-13 17:09:09 +02:00
|
|
|
self._avail_regions = {"us-east":"http://l2.io/ip",
|
2017-06-05 09:30:23 +02:00
|
|
|
"us-central":"http://whatismyip.akamai.com",
|
|
|
|
"us-west":"http://ipv4bot.whatismyipaddress.com",
|
|
|
|
"pl":"http://ip.42.pl/raw",
|
|
|
|
"de":"http://myexternalip.com/raw",
|
|
|
|
"nl":"http://tnx.nl/ip",
|
|
|
|
"uk":"http://ident.me"}
|
|
|
|
self._region = self.parameter("region", "us-central")
|
2017-06-05 09:53:44 +02:00
|
|
|
self._service = self.parameter("service", "")
|
2017-05-30 10:33:53 +02:00
|
|
|
self._ip = ""
|
|
|
|
|
|
|
|
|
|
|
|
def public_ip(self, widget):
|
|
|
|
return self._ip
|
|
|
|
|
|
|
|
def update(self, widgets):
|
|
|
|
try:
|
2017-06-05 09:53:44 +02:00
|
|
|
if self._service:
|
|
|
|
self.address = self._service
|
|
|
|
else:
|
|
|
|
self.address = self._avail_regions[self._region]
|
|
|
|
self._ip = get(self.address).text.rstrip()
|
2017-05-30 10:33:53 +02:00
|
|
|
except Exception:
|
2017-06-05 09:53:44 +02:00
|
|
|
self._ip = "No Connection"
|