博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python Ethical Hacking - MAC Address & How to Change(3)
阅读量:4929 次
发布时间:2019-06-11

本文共 2940 字,大约阅读时间需要 9 分钟。

SIMPLE ALGORITHM

Goal  -> Check if MAC address was changed.

Steps:

1. Execute and read ifconfig.

2. Read the mac address from the output.

3. Check if MAC in ifconfig is what the user requested.

4. Print appropriate message.

 

To find the MAC address, we can use the Pythex tool.

https://pythex.org/?regex=%5Cw%5Cw%3A%5Cw%5Cw%3A%5Cw%5Cw%3A%5Cw%5Cw%3A%5Cw%5Cw%3A%5Cw%5Cw&test_string=eth0%3A%20flags%3D4163%3CUP%2CBROADCAST%2CRUNNING%2CMULTICAST%3E%20%20mtu%201500%0A%20%20%20%20%20%20%20%20inet%2010.0.0.37%20%20netmask%20255.255.255.0%20%20broadcast%2010.0.0.255%0A%20%20%20%20%20%20%20%20inet6%20fe80%3A%3A211%3A22ff%3Afe33%3A4411%20%20prefixlen%2064%20%20scopeid%200x20%3Clink%3E%0A%20%20%20%20%20%20%20%20ether%2000%3A11%3A22%3A33%3A44%3A11%20%20txqueuelen%201000%20%20(Ethernet)%0A%20%20%20%20%20%20%20%20RX%20packets%20303175%20%20bytes%20386903781%20(368.9%20MiB)%0A%20%20%20%20%20%20%20%20RX%20errors%200%20%20dropped%200%20%20overruns%200%20%20frame%200%0A%20%20%20%20%20%20%20%20TX%20packets%2012392%20%20bytes%201023481%20(999.4%20KiB)%0A%20%20%20%20%20%20%20%20TX%20errors%200%20%20dropped%200%20overruns%200%20%20carrier%200%20%20collisions%200%0A&ignorecase=0&multiline=0&dotall=0&verbose=0

 

 

EX: Python Code 

#!/usr/bin/env pythonimport subprocessimport optparseimport redef get_arguments():    parser = optparse.OptionParser()    parser.add_option("-i", "--interface", dest="interface", help="Interface to change its MAC address")    parser.add_option("-m", "--mac", dest="new_mac", help="New MAC address")    (options, arguments) = parser.parse_args()    if not options.interface:        parser.error("[-] Please specify an interface, use --help for more info.")    elif not options.new_mac:        parser.error("[-] Please specify a new mac, use --help for more info.")    return optionsdef change_mac(interface, new_mac):    print("[+] Changing MAC address for " + interface + " to " + new_mac)    subprocess.call(["ifconfig", interface, "down"])    subprocess.call(["ifconfig", interface, "hw", "ether", new_mac])    subprocess.call(["ifconfig", interface, "up"])def get_current_mac(interface):    ifconfig_result = subprocess.check_output(["ifconfig", interface])    mac_address_search_result = re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w", ifconfig_result)    if mac_address_search_result:        return mac_address_search_result.group(0)    else:        print("[-] Could not read MAC address.")options = get_arguments()current_mac = get_current_mac(options.interface)print("Current MAC = " + str(current_mac))change_mac(options.interface, options.new_mac)current_mac = get_current_mac(options.interface)if current_mac == options.new_mac:    print("[+] MAC address was successfully changed to " + current_mac)else:    print("[-] MAC address did not get changed.")

 

Execute the following command to test the Python code:

python mac_changer.py -i eth0 -m 00:11:22:33:44:55

 

 

转载于:https://www.cnblogs.com/keepmoving1113/p/11334210.html

你可能感兴趣的文章
bzoj1036 树的统计Count
查看>>
Give your laptop some gaming power
查看>>
JS 高级总结
查看>>
idea maven 集成多模块 module
查看>>
hibernate 三种状态的转换
查看>>
gradle 删除指定目录中的文件和目录
查看>>
《大道至简》第二章读后感
查看>>
系统右键菜单(级联菜单)资料--cascading menus
查看>>
seaJs学习笔记
查看>>
Android Google官方文档解析之——System Permissions
查看>>
laravel 5.1 学习
查看>>
关于setTimeout(fn,0)
查看>>
hdu 3231
查看>>
【移动开发】自定义ProgressBar
查看>>
Js获取当前日期时间及其它操作
查看>>
java web eclipse中项目的加载过程
查看>>
开发Java Web程序
查看>>
session简介
查看>>
Codeforces 776E The Holmes Children
查看>>
LeetCode(66)题解: Plus One
查看>>