python - 列表项到整数转换触发python3中的语法错误
问题描述
import re
import socket
import sys
def Check(ip,port):
try:
s = socket.socket()
s.settimeout(0.3)
s.connect((ip,port))
return s.recv(512)
except:
pass
def Scan():
start = sys.argv[1]
end = sys.argv[2]
endip = end.partition('.')
currentip = start.split('.')
while not (currentip == endip):
targetip = currentip[0]+"."+currentip[1]+"."+currentip[2]+"."+currentip[3]
print("Checking: "+targetip+"\n")
result = Check(targetip,21)
if result:
if re.search("FTP",result.decode('utf-8')):
retard = open('ftps.txt','a')
retard.write(targetip+"\n")
retard.close()
if (int(currentip[3]) < 255) and (int(currentip[0]) != int(endip[0])) and (int(currentip[1]) != int(endip[1])) and (int(currentip[2]) != int(endip[2])) and (int(currentip[3]) != int(endip[3])+1):
int(currentip[3]) += 1
elif (int(currentip[3]) == 255) and (int(currentip[0]) != int(endip[0])) and (int(currentip[1]) != int(endip[1])) and (int(currentip[2]) != int(endip[2])) and (int(currentip[3]) != int(endip[3])+1):
if (int(currentip[2]) < 255):
int(currentip[2]) += 1
int(currentip[3]) = 0
elif (int(currentip[2]) == 255):
if (int(currentip[1]) < 255):
int(currentip[1]) += 1
int(currentip[2]) = 0
int(currentip[3]) = 0
elif (int(currentip[0]) < int(endip[0])) and (int(currentip[0]) != 255) and (int(currentip[1]) == 255):
int(currentip[0]) += 1
int(currentip[1]) = 0
int(currentip[2]) = 0
int(currentip[3]) = 0
Scan()
int(currentip[0]) += 1
导致错误,而以完全相同的方式转换的其他项目的转换触发无。
File "ftpscan.py", line 46
int(currentip[0]) += 1
^
SyntaxError: cannot assign to function call
解决方案
基本上, i += 1
, 与i = i + 1
在您的情况下
int(currentip[0]) += 1
,与int(currentip[0]) = int(currentip[0]) + 1
因此,从技术上讲,您不能分配给函数调用。相反,这应该有效
currentip[0] = int(currentip[0]) + 1
推荐阅读
- html - 有没有办法将所有这些元素绑定在一起以更改屏幕尺寸/缩放?
- sql-server - t-sql select count(*) to integer 变量创建异常不能是 varchar 类型不能转换为 int?
- php - 重新排列使用多个 foreach 条件的逻辑
- python - 重新连接后读取订阅的 MQTT 消息
- java - 如何在 Spring Boot 中使用 Envers 在审计表中添加字段
- mysql - 从具有内连接的表中选择最大值
- javascript - 如何通过从 JavaScript 中的数组对象生成数据来更新 HTML 中的内容?
- swiftui - SwiftUI 中免费的可扩展 List 有什么要求?
- javascript - 从 Edge 浏览器时间输入类型中删除图标和下拉菜单
- python-3.x - 线程锁导致的死循环