I'm trying to create list of IP addresses from a SQL table using a for loop and run if condition on this table but the result return correct in the last results when list completed by for loop

def trunk():
    cnxn = pyodbc.connect()
    cursor = cnxn.cursor()
    cursor.execute("")
    lstipin = []
    lstip = []
    for row in cursor.fetchall():
        x1 = str(row[0])
        x2 = row[1]
        x3 = str(row[2])
        x4 = row[3]
        x5 = row[4]
        x = x1.split(".")
        y = x3.split("-")
        lstip.append(x5)
        ipint=int(ipaddress.IPv4Address(x5))
        lstipin.append(int(ipaddress.IPv4Address(x5)))
        prip=ipint -1
        if (x[0] == y[0] and "I0P3" in x1) and ("POC3" and "POC2" in x3):
            if prip in lstipin:
                print(prip, "  ", str(ipaddress.IPv4Address(prip)), "  ", x5)

            print("True", "   ", x1, "   ", x3, "   ", x5)
        else:
            print("False EDESC", x1, x3, x5)

    print(lstipin, "\n",len(lstipin))
    print(lstip, "\n", len(lstip))

    cnxn.commit()

def main():

    trunk()

main()

0 Answers