From d76766fb5fc28940d4960d4ed2d693f9fc08e7c4 Mon Sep 17 00:00:00 2001 From: paulussimanjuntak Date: Fri, 19 Oct 2018 19:54:25 +0800 Subject: [PATCH] first commit --- README.md | 1 + ping-service.py | 77 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 README.md create mode 100755 ping-service.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..eb74650 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +ping-service.py diff --git a/ping-service.py b/ping-service.py new file mode 100755 index 0000000..7fe780e --- /dev/null +++ b/ping-service.py @@ -0,0 +1,77 @@ +#!/usr/bin/python + +import sys, subprocess, re +from os import system as MaManX + +def make_secure(): + unsafe_word = ['__import__', 'eval', 'execfile', 'file', 'input', 'compile', 'reload'] + for unsafe in unsafe_word: + del __builtins__.__dict__[unsafe] + +class Unbuffered(object): + def __init__(self, stream): + self.stream = stream + def write(self, data): + self.stream.write(data) + self.stream.flush() + def writelines(self, datas): + self.stream.writelines(datas) + self.stream.flush() + def __getattr__(self, attr): + return getattr(self.stream, attr) + +sys.stdout = Unbuffered(sys.stdout) + +def banner(): + return ''' +\033[1;32mWELCOME TO MAMANX PINX SERVICE\033[1;m\033[1;31m + _ __ _____ _ _____ _____ _ _ _____ _____ _____ _____ _ _ _____ _____ _____ +| | / // ___|| | | ___ \|_ _|| \ | || __ \ / ___|| ___|| ___ \| | | ||_ _|/ __ \| ___| +| |/ / \ `--. | | | |_/ / | | | \| || | \/ \ `--. | |__ | |_/ /| | | | | | | / \/| |__ +| \ `--. \| | | __/ | | | . ` || | __ `--. \| __| | / | | | | | | | | | __| +| |\ \/\__/ /| |____ | | _| |_ | |\ || |_\ \ /\__/ /| |___ | |\ \ \ \./ / _| |_ | \__/\| |___ +\_| \_/\____/ \_____/ \_| \___/ \_| \_/ \____/ \____/ \____/ \_| \_| \___/ \___/ \_____/\____/ + \033[1;m +\033[1;32mversion [beta 1.1 MAMANK]\033[1;m + ''' +def displayMenu(): + return ''' +Choose a ksl ping service: + 1. Ping only one time + 2. Ping multiple times + 3. Exit MaManX +''' + +def main(): + make_secure() + print banner() + print displayMenu() + + userNumber = raw_input("Masukkan pilihan (1-3): ") + if userNumber == "1" : + host = raw_input("\nMasukkan alamat host : ") + p1 = subprocess.Popen(['ping','-c 5', host], stdout=subprocess.PIPE) + output = p1.communicate()[0] + print output + exit() + elif userNumber == "2" : + user = int(raw_input("\nMasukkan jumlah host: ")) + while user <= 1: + user = int(raw_input("\nMasukkan host lebih dari 1 MaManX: ")) + for o in range(user): + host = raw_input("Masukkan alamat host ke " +str(o+1) +" : ") + hosts= re.sub('[|,;]', '', host) + pings = MaManX('ping -c 5 ' + hosts ) + if (pings == 0): + print host.upper(), "IS UP MAMANX" + else : + print host.upper(), "IS LOST MAMANX" + print "" + elif userNumber == "3" : + print "\nTerimakasih telah menggunakan jasa kami MaManX" + exit() + else : + print "\nMaManX salah masukkin acchh :(" + exit() + +main()