amr_aly

Check_mac_address_decorator

Jul 22nd, 2021
1,718
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os , re , uuid
  2. # Decorator for check mac address
  3. def auth_required(function):
  4.     def wrap(request, *args, **kwargs):
  5.         # joins elements of getnode() after each 2 digits.
  6.         # using regex expression
  7.         label = os.environ.get('SERIAL')
  8.         # print (label)
  9.         mac = ':'.join(re.findall('..', '%012x' % uuid.getnode()))
  10.         # print (mac)
  11.         if mac == label:
  12.             # messages.success(request, 'you are authorized')
  13.             return function(request, *args, **kwargs)
  14.         else:
  15.             # messages.success(request, 'you are not authorized')
  16.             raise PermissionDenied
  17.  
  18.     wrap.__doc__ = function.__doc__
  19.     wrap.__name__ = function.__name__
  20.     return wrap
RAW Paste Data