I am building a packet-sending tool that should check if servers are online. Well, I want to send TCP packets to a chosen server while it displays the amount of packets currently sent. I have the below script to do what I want, but it's not quite working :/. I also have some code that I've attempted to modify to achieve the same things, but it is a different type of display...
My Code:
nums = []
nums.append(x + 1)
_range = ['_']
for _ in _range:
for x in nums:
# sys.stdout.write("\b Packet [ %s ] sent!" % x)
sys.stdout.write( " Packet [ %s ] sent!" % x )
sys.stdout.flush()
time.sleep(.5)
pass
and the Correct code:
#!/usr/bin/env python
import sys
import time
print "loading...\\",
while True:
syms = ['\\', '|', '/', '-']
bs = '\b'
for _ in range(5):
for sym in syms:
sys.stdout.write("\b%s" % sym)
sys.stdout.flush()
time.sleep(.5)
pass
print("\n")
I need the same thing as the correct code, except for it to display the amount of packets sent in real-time. Example:
Packet [ 3 ] sent!
(previous txt cleared)
Packet [ 4 ] sent!
(previous txt cleared)
Packet [ 5 ] sent!
(previous txt cleared)
and so on...
I hope you can see what I'm trying to depict here. If not, please do request more info and I'll do my best to explain. Sorry about this issue though, I'm sure it's an simple fix but I'm still learning python to be honest.. :/
Thanks so much in advance!
You need to put an \r
return in your sys.stdout.write
:
sys.stdout.write( " \rPacket [ %s ] sent!" % x )
That way the next print will overwrite it.