Python for Hacking
MAC Changer
Algorithm Step 2
Step2: Read the mac address from output.
To read the MAC Address from output we use RegEx method.
RegEx
- A RegEx or Regular Expression, is a sequence of characters that forms a search pattern.
- RegEx can be used to check if a string contains the specified search pattern.
- Uses rules to match the pattern
Rules
- / Escape special characters
- . Matches any characters
- ^ Matches beginning of string
- $ Matches end of string
- [5b-d] Matches any chars '5', 'b', 'c' or 'd'
- [^a-c6] Matches any char except 'a', 'b', 'c' or '6'
- R|S Matches either regex R or regex S
- () Creates a capture group and indicates precedence
- * 0 or more (append ? for non-greedy)
- + 1 or more (append ? for non-greedy)
- ? 0 or 1 (append ? for non-greedy)
- {m} exactly mm occurrences
- {m, n} from m to n. m defaults to 0, n to infinity
- {m, n}? from m to n, as few as possible
- \A start of string
- \b matches empty string at word boundary (between \w and \W)
- \B matches empty string not at word boundary
- \d digit
- \D non-digit
- \s whitespace: [ \t\n\r\f\v]
- \S non-whitespace
- \w alphanumeric: [0-9a-zA-Z_]
- \W non-alphanumeric
- \Z end of string
- \g<id> matches a previously defined group
- (?iLmsux) matches empty string, sets re.X flags
- (?:...) non-capturing version of regular parentheses
- (?P...) matches whatever matched previously named group
- (?P=) digit
- (?#...) a comment; ignored
- (?=...) lookahead assertion: matches without consuming
- (?!...) negative lookahead assertion
- (?<=...) lookbehind assertion: matches if preceded
- (?<!...) negative lookbehind assertion
- (?(id)yes|no) match 'yes' if group 'id' matched, else 'no'
In our case we need to find MAC Address from the ifconfig result for that we use the rule given below.
\w\w:\w\w:\w\w:\w\w:\w\w:\w\w

No comments:
Post a Comment