Hi there! I new learner in Python. And just couldn't get threading. I wrote this script.
import sys import MySQLdb if len(sys.argv)!=3: """the program name, mac and ip makes three""" """stop program and send error""" sys.exit("Must provide mac and ip!") mac = sys.argv ip = sys.argv print 'Connected to server' #saving ip to database! # Open database connection db = MySQLdb.connect("localhost","user","pass","dbname" ) # prepare a cursor object using cursor() method cursor = db.cursor() # Prepare SQL query to UPDATE required records sql = "UPDATE mac_list SET ip ='"+ip+"' WHERE mac='"+mac+"'" try: # Execute the SQL command cursor.execute(sql) # Commit your changes in the database db.commit() print (mac+' and '+ip+' entered to database') except: # Rollback in case there is any error db.rollback() print ('something went wrong') # disconnect from server db.close()
And I want to thread it. So that when called it won't have to wait for the previous call. How can I do that?
Criticisms on above code will be greatly appreciated!
Thanks in advance!
P.S. An example call would be
python getmacip.py [some-MAC] [some-IP]