简体   繁体   English

从PC获取Mac地址并进行比较失败

[英]Getting mac address from pc and compare it fails

I am using python 2.7 with sqlite3 我在sqlite3中使用python 2.7

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 : 我创建了一个空表,并创建了一个函数来检查表是否为空,它将获取当前PC的mac地址并将其存储在表中,每次程序工作时它都将工作,然后如果表不为空,调用另一个函数,该函数获取当前的mac并将其与存储在表中的mac进行比较,如果其不相同,则关闭程序,这是代码:

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 一切正常,程序已经捕获了mac地址,然后将其添加到表中,但是,在所有情况下,它都显示了错误,该错误将在程序之后关闭程序..忽略了if-else语句,该语句应停止该错误显示

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 主要问题是没有回溯错误,尽管满足了if mac == table_mac:的条件,但它仅显示最后的else语句

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 pass ,然后为两个功能添加自动运行命令,效果很好

active()
checking()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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