Reputation: 21
!/usr/bin/env python3
import random
import socket
import time
import sys
import os
print ('Ping Of Death')
os.system("clear")
print
ip_death = input("ip:")
packetsize = input("size:")
print (ip_death)
os.system("ping ip_death, -s packetsize ")
and the output I get is
ping: ip_death,: Name or service not known
I know the variables are defined because of print (ip_death)
that I have tested and always comes out with my input.
I'm new to python and just wondering how I can run both of these variables in the in one command. If wonder I'm trying to run Ping example.com -s "size of packet"
.
Upvotes: 1
Views: 166
Reputation: 5746
os.system(f"ping {ip_death}, -s {packetsize} ")
You can use f-strings
to insert a variable directly into a string. f-strings
are defined by f"{variable}"
Note:
os.system(f"ping {ip_death}, -s {packetsize} ")
Will still fail, the comma will throw an error in cmd
,
Ping request could not find host 192.168.0.1,. Please check the name and try again.
You need to remove the comma for it to work;
os.system(f"ping {ip_death} -s {packetsize} ")
ping 192.168.0.1 -s 1
Pinging 192.168.0.1 with 32 bytes of data:
Reply from 192.168.0.1: bytes=32 time<1ms TTL=255
Timestamp: 192.168.0.1 : 4742664
Upvotes: 2
Reputation: 31339
You need to format the string:
os.system("ping {}, -s {}".format(ip_death, packet_size))
You can also verify you're doing the right thing by printing the command before executing it:
command = "ping {}, -s {}".format(ip_death, packet_size)
print(command) # see that its what you wanted to execute
os.system(command)
Currently you just baked the names into the strings. Python doesn't automagically know what it should format and what it shouldn't.
Also - black hat hacking is bad <3
Upvotes: 2