简体   繁体   中英

Getting mac address from pc and compare it fails

I am using python 2.7 with sqlite3

I've created an empty table to and a function that checks if the table is empty it gets the mac address of the current pc and stores it at the table, it works every time the program work, then if the table is not empty it calls another function that gets the current mac and compares it to the one stored in the table , then closes the program if its not the same ,, Here is the code :

def active():
    from uuid import getnode as get_mac
    mac = get_mac()
    name = 666
    conn = sqlite3.connect('storage/container.db')
    conn.row_factory = lambda c, row: row[0]
    c = conn.cursor()
    c.execute("SELECT COUNT(*) FROM mac")
    count = c.fetchall()[0]
    conn.close()
    if count == 0:
        conn = sqlite3.connect('storage/container.db')
        conn.row_factory = lambda c, row: row[0]
        c = conn.cursor()
        c.execute("INSERT INTO mac (name, macAddress) VALUES (?, ?)", (name, mac, ))
        conn.commit()
        conn.close()
    else:
        checking()




def checking():
    from uuid import getnode as get_mac
    mac = get_mac()
    conn = sqlite3.connect('storage/container.db')
    conn.row_factory = lambda c, row: row[0]
    c = conn.cursor()
    c.execute("SELECT macAddress FROM mac WHERE name = 666")    
    table_mac = c.fetchall()[0]
    if mac == table_mac:
        critical_title1 = 'أهلاً بك '
        critical_title = critical_title1.decode('utf-8')
        critical_msg1 = "تم تأكيد صلاحية النسخة للإستخدام "
        critical_msg = critical_msg1.decode('utf-8')
        QtGui.QMessageBox.information(mainWindow, critical_title, critical_msg)
    else:
        critical_title1 = 'خطأ'
        critical_title = critical_title1.decode('utf-8')
        critical_msg1 = "لا يمكنك إستخدام البرنامج من دون شراء نسختك الخاصة"
        critical_msg = critical_msg1.decode('utf-8')
        QtGui.QMessageBox.critical(mainWindow, critical_title, critical_msg)
        sys.exit()

everything goes fine and the program already catches the mac address then add it to the table, but then, in all cases, it shows the error that closes the program after it .. ignoring the if-else statement that should stop the error from being showed

i think the problem is here :

if mac == table_mac:
    critical_title1 = 'أهلاً بك '
    critical_title = critical_title1.decode('utf-8')
    critical_msg1 = "تم تأكيد صلاحية النسخة للإستخدام "
    critical_msg = critical_msg1.decode('utf-8')
    QtGui.QMessageBox.information(mainWindow, critical_title, critical_msg)
else:
    critical_title1 = 'خطأ'
    critical_title = critical_title1.decode('utf-8')
    critical_msg1 = "لا يمكنك إستخدام البرنامج من دون شراء نسختك الخاصة"
    critical_msg = critical_msg1.decode('utf-8')
    QtGui.QMessageBox.critical(mainWindow, critical_title, critical_msg)
    sys.exit()

Note

the main problem that there is no traceback error it just shows the last else statement despite the condition if mac == table_mac: is met

The problem was that I tried to call the 2nd function from inside the first one I just changed

else:
    checking()

to pass and then add autorun command for both functions and it works great

active()
checking()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM