Example #1
0
def ping(text, reply, notice):
    """<host> [count] - pings <host> [count] times"""

    args = text.split(' ')
    host = args[0]

    # check for a second argument and set the ping count
    if len(args) > 1:
        count = int(args[1])
        if count > 20:
            count = 20
    else:
        count = 5

    count = str(count)

    if os.name == "nt":
        args = ["ping", "-n", count, host]
    else:
        args = ["ping", "-c", count, host]

    notice("Attempting to ping {} {} times...".format(host, count))
    try:
        pingcmd = subprocess.check_output(args).decode("utf-8")
    except subprocess.CalledProcessError:
        return "Could not ping host."

    if re.search("(?:not find host|timed out|unknown host)", pingcmd, re.I):
        return "Could not ping host."

    if os.name == "nt":
        m = re.search(win_ping_regex, pingcmd)
        r = int(m.group(2)) - int(m.group(1))
        min, max, avg, range, count = str(m.group(1)), str(m.group(2)), str(
            m.group(3)), str(r), str(count)
    # return "min: %sms, max: %sms, average: %sms, range: %sms, count: %s" \
    #			   % (m.group(1), m.group(2), m.group(3), r, count)
    else:
        m = re.search(unix_ping_regex, pingcmd)
        min, max, avg, range, count = str(m.group(1)), str(m.group(3)), str(
            m.group(2)), str(m.group(4)), str(count)
    # return "min: %sms, max: %sms, average: %sms, range: %sms, count: %s" \
    #			   % (m.group(1), m.group(3), m.group(2), m.group(4), count)

    # Build up a toreply str
    toreply = "min: " + colorize(min, 20, 50) + ", max: " + colorize(
        max, 30,
        100) + ", average: " + colorize(avg, 25, 75) + ", range: " + colorize(
            range, 5, 10) + ", count: " + count

    return parse(host + " : " + toreply)
Example #2
0
def ping(text, reply, notice):
    """<host> [count] - pings <host> [count] times"""

    args = text.split(' ')
    host = args[0]

    # check for a second argument and set the ping count
    if len(args) > 1:
        count = int(args[1])
        if count > 20:
            count = 20
    else:
        count = 5

    count = str(count)

    if os.name == "nt":
        args = ["ping", "-n", count, host]
    else:
        args = ["ping", "-c", count, host]

    notice("Attempting to ping {} {} times...".format(host, count))
    try:
        pingcmd = subprocess.check_output(args).decode("utf-8")
    except subprocess.CalledProcessError:
        return "Could not ping host."

    if re.search("(?:not find host|timed out|unknown host)", pingcmd, re.I):
        return "Could not ping host."

    if os.name == "nt":
        m = re.search(win_ping_regex, pingcmd)
        r = int(m.group(2)) - int(m.group(1))
        min, max, avg, range, count = str(m.group(1)), str(m.group(2)), str(m.group(3)), str(r), str(count)
    # return "min: %sms, max: %sms, average: %sms, range: %sms, count: %s" \
    #			   % (m.group(1), m.group(2), m.group(3), r, count)
    else:
        m = re.search(unix_ping_regex, pingcmd)
        min, max, avg, range, count = str(m.group(1)), str(m.group(3)), str(m.group(2)), str(m.group(4)), str(count)
    # return "min: %sms, max: %sms, average: %sms, range: %sms, count: %s" \
    #			   % (m.group(1), m.group(3), m.group(2), m.group(4), count)

    # Build up a toreply str
    toreply = "min: " + colorize(min, 20, 50) + ", max: " + colorize(max, 30, 100) + ", average: " + colorize(avg, 25,
                                                                                                              75) + ", range: " + colorize(
        range, 5, 10) + ", count: " + count

    return parse(host + " : " + toreply)
Example #3
0
def virhash(text, notice, nick):
    if getTokens(nick) < 1000:
        notice(
            "You don't have enough tokens to check a file on virus total (1000 needed)... Help a little more !"
        )
        return None

    if not text:
        notice("Please specify an hash (md5, sha1, ...) in this command")
        return None

    takeTokens(50, nick, notice)

    hash = str(text)

    parsedDict = VTHashCheck(hash)
    if int(parsedDict["response_code"]) == 1:
        toreply = parse("Last scan did on " + str(parsedDict["scan_date"]) +
                        ". Positives AV : " +
                        str(colorize(parsedDict["positives"], 1, 10)) + "/" +
                        str(parsedDict["total"]) + "\nMore info at : " +
                        str(parsedDict["permalink"]))
    else:
        toreply = "An error occured ! n°" + str(
            parsedDict["response_code"]) + " : " + str(
                parsedDict["verbose_msg"])
        if "." in hash:
            toreply += "\nMaybe launching the check with !virustotalweb URL could help !"

    return toreply
Example #4
0
def airparif(text):

    try:
        arg = text
    except:
        arg = "jour"

    if arg == "hier":
        url = "http://www.airparif.asso.fr/appli/api/indice?date=hier"
    elif arg == "demain":
        url = "http://www.airparif.asso.fr/appli/api/indice?date=demain"
    else:
        url = "http://www.airparif.asso.fr/appli/api/indice?date=jour"
    try:
        req = urllib.request.Request(url)
        response = urllib.request.urlopen(req)
        response = response.read().decode("utf-8")
        response = json.loads(response)
    except Exception as e:
        return "Aie ! Une erreur est survenue avec l'api de airparif : " + str(
            e)

    toreply = ""

    try:
        response["indices"]
        toreply = "Pas de données disponibles pour demain avant 11 heures !"
        return toreply

    except:
        pass

    toreply = "Pour le " + response[
        "date"] + " l'indice de pollution est de " + colorize(
            response["global"]["indice"], 50, 75) + "\n"
    toreply += "No2 : " + colorize(
        response["no2"]["indice"], 50, 75) + ", o3 : " + colorize(
            response["o3"]["indice"], 50, 75) + ", pm10 : " + colorize(
                response["pm10"]["indice"], 50, 75) + "\n"
    toreply += "Plus d'infos sur la carte : " + response["global"]["url_carte"]
    toreply = parse(toreply)
    return toreply
Example #5
0
def airparif(text):

    try:
        arg = text
    except:
        arg = "jour"

    if arg == "hier" :
        url = "http://www.airparif.asso.fr/appli/api/indice?date=hier"
    elif arg == "demain":
        url = "http://www.airparif.asso.fr/appli/api/indice?date=demain"
    else:
        url = "http://www.airparif.asso.fr/appli/api/indice?date=jour"
    try:
        req = urllib.request.Request(url)
        response = urllib.request.urlopen(req)
        response = response.read().decode("utf-8")
        response = json.loads(response)
    except Exception as e:
        return "Aie ! Une erreur est survenue avec l'api de airparif : " + str(e)

    toreply = ""

    try:
        response["indices"]
        toreply = "Pas de données disponibles pour demain avant 11 heures !"
        return toreply

    except:
        pass

    toreply = "Pour le " + response["date"] + " l'indice de pollution est de " + colorize(response["global"]["indice"], 50, 75) + "\n"
    toreply += "No2 : " + colorize(response["no2"]["indice"], 50, 75) + ", o3 : " + colorize(response["o3"]["indice"], 50, 75) + ", pm10 : " + colorize(response["pm10"]["indice"], 50, 75) + "\n"
    toreply += "Plus d'infos sur la carte : " + response["global"]["url_carte"]
    toreply = parse(toreply)
    return toreply