Check Valid Mac Address from Database in Python code -


i want add mac address (validation) check before python script runs. there have database online. in script want add mac address check before runs script.

my script have right now

downloading files web server

so script wanna after

get mac adress android device. check mac address valid or not using pre-def list (db file)

if valid then

downloading files web server

this simple python program in finding valid mac address

import re  def checkmac(x):       if re.match("[0-9a-f]{2}([-:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", x.lower()):             return 1     else:             return 0  print checkmac("aa:bb:cc:dd:ee:ff") print checkmac("00-11-22-33-44-66") print checkmac("1 2 3 4 5 6 7 8 9 b c") print checkmac("this not mac") 

it accepts 12 hex digits either : or - separators between pairs (but separator must uniform... either separators : or -).

this explanation:

[0-9a-f] means hexadecimal digit

{2} means want 2 of them

[-:] means either dash or colon. note dash first char doesn't mean range means itself. atom enclosed in parenthesis can reused later reference.

[0-9a-f]{2} pair of hexadecimal digits

\1 means want match same expression matched before separator. guarantees uniformity. note regexp syntax \1 i'm using regular string backslash must escaped doubling it.

[0-9a-f]{2} pair of hex digits

{4} previous parenthesized block must repeated 4 times, giving total of 6 pairs of digits: ( ) * 4

$ string must end right after them


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -