#๐Ÿ”’ sending and receivingg packets via socket

9 messages ยท Page 1 of 1 (latest)

wanton glacier
#
import socket
import random
import time


sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) #opens a new socket

bytes = random._urandom(1024) #creates packet

ip = input("Target IP:")

port = input("Port :")

duration = input("duration :")

timeout = time.time() + duration
sent = 0

while True :
    if time.time() > timeout:
        break
    else:
        pass
    sock.sendto(bytes,(ip, port))
    sent = sent + 1
    print ("sent %s packet to %s through port %s")%(sent, ip , port)
    
#Traceback (most recent call last):
  #File "/home/arctichonour/packets.py", line 16, in <module>
    #timeout = time.time() + duration
#TypeError: unsupported operand type(s) for +: 'float' and 'str'

sterile reefBOT
#

@wanton glacier

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

misty latch
#

This isn't a socket problem. Remember that input always returns a string. If you want to interpret what the user entered as a number, you need to do that conversion yourself using int or float before doing math on it.

wanton glacier
#

oh silly mistake

misty latch
#

Just a tip, always read the error carefully. It's telling you exactly what the problem is.

#

float and str means that the left operand to + was a float, and the right operand was a string.

wanton glacier
#

!close

sterile reefBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.