eping代码代替ping命令
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @version: v1.0 @author: zyjsuper @contact: zyj_super@outlook.com @site: https://www.cnblogs.com/heycomputer @software: PyCharm @file: eping.py @time: 2019/10/6 19:35 """ # Extented Ping import sys import platform import os if __name__ == '__main__': if len(sys.argv) == 1: print('Usage example: eping http://www.baidu.com') sys.exit(0) target = sys.argv[1].lower() if not target.startswith('http'): target = 'http://%s' % target if sys.version_info >= (3, 0): from urllib.parse import urlparse host = urlparse(target, 'http').hostname else: import urlparse host = urlparse.urlparse(target, 'http').hostname param_count = '-c4 ' if platform.system() != 'Windows' else '' os.system('ping %s%s' % (param_count, host))