Sunday, April 20, 2025

Python Keyboard Arguments

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

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...