We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 407d523 commit 35fa09dCopy full SHA for 35fa09d
addons/source-python/packages/source-python/core/__init__.py
@@ -23,6 +23,8 @@
23
from platform import system
24
# Sys
25
import sys
26
+# Urllib
27
+from urllib.request import urlopen
28
# Weakref
29
from weakref import WeakValueDictionary
30
@@ -62,6 +64,7 @@
62
64
'console_message',
63
65
'echo_console',
66
'get_interface',
67
+ 'get_public_ip',
68
'ignore_unicode_errors',
69
)
70
@@ -203,3 +206,15 @@ def ignore_unicode_errors(errors='ignore'):
203
206
yield
204
207
finally:
205
208
codecs.register_error('strict', old_handler)
209
+
210
211
+def get_public_ip():
212
+ """Return the server's public IPv4.
213
214
+ :rtype: str
215
216
+ .. note::
217
218
+ This functions makes a call to http://ip.42.pl/raw to retrieve the public IP.
219
+ """
220
+ return urlopen('http://ip.42.pl/raw').read().decode()
0 commit comments