Skip to content

Instantly share code, notes, and snippets.

@rossdylan
Created July 29, 2010 01:58
Show Gist options
  • Save rossdylan/496993 to your computer and use it in GitHub Desktop.
Save rossdylan/496993 to your computer and use it in GitHub Desktop.
"""
Module that wraps around ping and traceroute. The X version uses a new threading thingy
"""
import procThread
import threading
__info__ = {
"Author": "Ross Delinger",
"Version": "1.0",
"Dependencies": ["ping", "traceroute"]
}
def onLoad():
@command("ping", 1)
def ping(ctx, cmd, arg, *args):
address = args[0]
shellCmd = ["ping", "-c", "5", address]
pt = procThread(shellCmd, ctx)
pt.start()
@command(["traceroute", "tr", "tracert"], 1)
def tracert(ctx, cmd, arg, *args):
address = args[0]
shellCmd = []
if os.name == 'nt':
shellCmd = ["tracert", address]
else:
shellCmd = ["traceroute", address]
process = MODIFIED_subprocess.Popen(shellCmd, stdin=MODIFIED_subprocess.PIPE, stdout=MODIFIED_subprocess.PIPE, stderr=MODIFIED_subprocess.STDOUT)
output = process.communicate()
listOut = list(output)
for l in listOut:
if l != None:
ctx.reply(l, "TraceRoute")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment