Created
February 23, 2026 20:48
-
-
Save CarlFK/bd0da75a01d85e7848e6571698d68946 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from subprocess import Popen, PIPE, TimeoutExpired | |
| import os | |
| def ping(ip): | |
| cmd = ["ping", | |
| "-c", "3", | |
| "-w", "5", | |
| ip] | |
| proc = Popen(cmd, | |
| stdin=PIPE, stdout=PIPE,stderr=PIPE) | |
| os.set_blocking(proc.stdout.fileno(), False) | |
| while proc.poll() is None: | |
| line=proc.stdout.readline() | |
| line=line.decode().strip() | |
| if line: | |
| print(line) | |
| lines=proc.stdout.read() | |
| lines=lines.decode() | |
| for line in lines.split('\n'): | |
| line=line.strip() | |
| if line: | |
| print(line) | |
| def main(): | |
| ping("127.0.0.1") | |
| if __name__=='__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment