TransWikia.com

list item to integer conversion triggers syntax error in python3

Stack Overflow Asked by StYl3z on December 16, 2021

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 causes an error while the conversion of other items that are exactly the same way converted trigger none.

  File "ftpscan.py", line 46
    int(currentip[0]) += 1
    ^
SyntaxError: cannot assign to function call

3 Answers

"""
FTPScan by StYl3z
Greetz fly out to:
L0rd,Legolas,Prometheus,Smoky-Ice,izibitzi,Waterb0ng,MaXtOr
usage: python3 ftpscan.py <startip> <endip>
"""
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.split('.')
    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 == 0:
            if re.search("FTP",result.decode('utf-8')):
                retard = open('ftps.txt','a')
                retard.write(targetip+"n")
                retard.close()
        if not (int(currentip[3])==255):
            currentip[3] = int(currentip[3])+1
            currentip[3] = str(currentip[3])
        else:
            if not(int(currentip[2])==255):
                currentip[2] = int(currentip[2])+1
                currentip[2] = str(currentip[2])
                currentip[3] = str("0")
            else:
                if not(int(currentip[1])==255):
                    currentip[1] = int(currentip[1])+1
                    currentip[1] = str(currentip[1])
                    currentip[2] = str("0")
                    currentip[3] = str("0")                    
                else:
                    if not(int(currentip[0])==255):
                        currentip[0] = int(currentip[0])+1
                        currentip[0] = str(currentip[0])
                        currentip[1] = str("0")
                        currentip[2] = str("0")
                        currentip[3] = str("0")
Scan()

is the way it's working, thanks for trying to help me, i figured it out myself

Answered by StYl3z on December 16, 2021

Basically, i += 1, is same as i = i + 1

in your case int(currentip[0]) += 1 , is same as int(currentip[0]) = int(currentip[0]) + 1

So, technically you can't assign to the function call. Instead, this should work

currentip[0] = int(currentip[0]) + 1

Answered by roshan ok on December 16, 2021

You are trying to increment a number (what int() returns) as opposed to the contents of a variable.

Answered by Scott Hunter on December 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP