This function will ping some IP/domain with 5 packets. With "-n" number of packets will be part of "ping" instruction.
Pay attention about spaces, they are important while constructing command.
If you are on Linux use "-c", "-n" is for Windows machines.
import os
def custom_ping(ip, packets):
os.system("ping -n " + str(packets) + " " + ip)
custom_ping("127.0.0.1", 5)
But this is more usable, because we can grab domain and packet number from keyboard without messing around directly with function every time:
import os
def custom_ping(ip, packets):
os.system("ping -n " + str(packets) + " " + ip)
real_ip = input("Please Enter IP: ")
real_packets = input("Number of packets: ")
custom_ping(real_ip, real_packets)
No comments:
Post a Comment