Skip to content

Instantly share code, notes, and snippets.

@cdot65
Created March 29, 2023 20:32
Show Gist options
  • Save cdot65/71ddd623416f32de5adc395a0fed93e5 to your computer and use it in GitHub Desktop.
Save cdot65/71ddd623416f32de5adc395a0fed93e5 to your computer and use it in GitHub Desktop.
Continuous Ping
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)
@cdot65
Copy link
Author

cdot65 commented Mar 29, 2023

python continuous_traceroute.py example.com 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment