这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ target/

#Ipython Notebook
.ipynb_checkpoints

# PyCharm stuff
.idea
1 change: 1 addition & 0 deletions modules/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
'quote',
'request',
'wiki',
'ping',
]
26 changes: 26 additions & 0 deletions modules/src/ping.py
Original file line number Diff line number Diff line change
@@ -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"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this platform thing is bugging me!

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

8 changes: 8 additions & 0 deletions modules/tests/test_ping.py
Original file line number Diff line number Diff line change
@@ -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])