Skip to content

Commit 35fa09d

Browse files
committed
Added feature requested in #155
1 parent 407d523 commit 35fa09d

File tree

1 file changed

+15
-0
lines changed
  • addons/source-python/packages/source-python/core

1 file changed

+15
-0
lines changed

addons/source-python/packages/source-python/core/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
from platform import system
2424
# Sys
2525
import sys
26+
# Urllib
27+
from urllib.request import urlopen
2628
# Weakref
2729
from weakref import WeakValueDictionary
2830

@@ -62,6 +64,7 @@
6264
'console_message',
6365
'echo_console',
6466
'get_interface',
67+
'get_public_ip',
6568
'ignore_unicode_errors',
6669
)
6770

@@ -203,3 +206,15 @@ def ignore_unicode_errors(errors='ignore'):
203206
yield
204207
finally:
205208
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

Comments
 (0)