Created
March 29, 2023 20:32
-
-
Save cdot65/71ddd623416f32de5adc395a0fed93e5 to your computer and use it in GitHub Desktop.
Continuous Ping
This file contains 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
import sys | |
import time | |
import platform | |
import subprocess | |
def continuous_traceroute(target, interval=1): | |
print(f"Starting continuous traceroute to {target} with an interval of {interval} seconds") | |
# Determine the appropriate command based on the operating system | |
command = "traceroute" if platform.system() != "Windows" else "tracert" | |
while True: | |
# Run the traceroute command | |
process = subprocess.Popen([command, target], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) | |
# Print the output in real-time | |
while True: | |
line = process.stdout.readline() | |
if not line: | |
break | |
print(line.strip()) | |
# Wait for the specified interval | |
time.sleep(interval) | |
if __name__ == "__main__": | |
if len(sys.argv) < 2: | |
print("Usage: python continuous_traceroute.py <target> [interval]") | |
sys.exit(1) | |
target = sys.argv[1] | |
interval = int(sys.argv[2]) if len(sys.argv) > 2 else 1 | |
continuous_traceroute(target, interval) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
python continuous_traceroute.py example.com 5