diff --git a/.gitignore b/.gitignore index 1dbc687d..4ee61c2f 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,6 @@ target/ #Ipython Notebook .ipynb_checkpoints + +# PyCharm stuff +.idea diff --git a/modules/src/__init__.py b/modules/src/__init__.py index 341a7d2f..478e7b4c 100644 --- a/modules/src/__init__.py +++ b/modules/src/__init__.py @@ -9,4 +9,5 @@ 'quote', 'request', 'wiki', + 'ping', ] diff --git a/modules/src/ping.py b/modules/src/ping.py new file mode 100644 index 00000000..c97322e2 --- /dev/null +++ b/modules/src/ping.py @@ -0,0 +1,26 @@ +import subprocess +import platform + +def process(input, entities=None): + + output = {'input': input} + + host = entities['host'][0]['value'] + + if not host: + output['success'] = False + output['output'] = "Please specify a host" + + return output + + ping_str = "-n 1" if platform.system().lower() == "windows" else "-c 1" + args = "ping " + " " + ping_str + " " + host + need_sh = False if platform.system().lower() == "windows" else True + + text = 'System reachable' if subprocess.call(args, shell=need_sh) == 0 else 'System unrechable' + + output['output'] = test + output['success'] = True + + return output + diff --git a/modules/tests/test_ping.py b/modules/tests/test_ping.py new file mode 100644 index 00000000..0f94bc40 --- /dev/null +++ b/modules/tests/test_ping.py @@ -0,0 +1,8 @@ +import modules + +def test_ping(): + assert ('ping' == modules.process_query('ping google.com')[0]) + assert ('ping' == modules.process_query('ping')[0]) + assert ('ping' != modules.process_query('something random')[0]) + +