Python Ethical Hacking - MAC Address & How to Change(2)
FUNCTIONS
- Set of instructions to carry out a task.
- Can take input, and return a result.
- Make the code clearer, reusable, and more abstract.
- input() function prompts the user to enter the value.
Rewrite the Python script using the function style.
#!/usr/bin/env python import subprocess
import optparse def 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"]) 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() change_mac(options.interface, options.new_mac)
Execute the following commands successfully to change the MAC.
python mac_changer.py -i eth0 -m :::::

Rewrite the Python script.
#!/usr/bin/env python import subprocess
import optparse def 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")
return parser.parse_args() def 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"]) (options, arguments) = get_arguments()
change_mac(options.interface, options.new_mac)
Execute the following commands successfully to change the MAC.
python mac_changer.py -i eth0 -m :::::33

Decision Making
- Execute code ONLY if a condition is true.
Rewrite the Python code using conditional statements.
#!/usr/bin/env python import subprocess
import optparse def 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 options def 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"]) options = get_arguments()
change_mac(options.interface, options.new_mac)
Test the script using the following commands.

Python Ethical Hacking - MAC Address & How to Change(2)的更多相关文章
- Python Ethical Hacking - MAC Address & How to Change(3)
SIMPLE ALGORITHM Goal -> Check if MAC address was changed. Steps: 1. Execute and read ifconfig. ...
- Python Ethical Hacking - MAC Address & How to Change(1)
MAC ADDRESS Media Access Control Permanent Physical Unique Assigned by manufacturer WHY CHANGE THE M ...
- Python Ethical Hacking - ARP Spoofing
Typical Network ARP Spoofing Why ARP Spoofing is possible: 1. Clients accept responses even if they ...
- Python Ethical Hacking - NETWORK_SCANNER(1)
NETWORK_SCANNER Discover all devices on the network. Display their IP address. Display their MAC add ...
- Python Ethical Hacking - NETWORK_SCANNER(2)
DICTIONARIES Similar to lists but use key instead of an index. LISTS List of values/elements, all ca ...
- Python Ethical Hacking - BeEF Framework(1)
Browser Exploitation Framework. Allows us to launch a number of attacks on a hooked target. Targets ...
- Python Ethical Hacking - WEB PENETRATION TESTING(1)
WHAT IS A WEBSITE Computer with OS and some servers. Apache, MySQL ...etc. Cotains web application. ...
- Python Ethical Hacking - BACKDOORS(8)
Cross-platform hacking All programs we wrote are pure python programs They do not rely on OS-specifi ...
- Python Ethical Hacking - BACKDOORS(7)
Handling Errors: If the client or server crashes, the connection will be lost. Backdoor crashes if: ...
随机推荐
- 《Redis开发与运维》
第1章 初识Redis 1. Redis介绍: Redis是一种基于键值对(key-value)的NoSQL数据库. 与很多键值对数据库不同的是,Redis中的值可以是由string(字符串).has ...
- s7-200高速脉冲输出与高速计数器讲解
s7-200高速脉冲输出与高速计数器讲解
- 键盘侠Linux教程(四)| 常用命令
前言 Linux命令并不可怕,只要熟悉日常的操作命令即可,其他不熟悉的命令,需要用到的时候可以查阅资料,熟能生巧. Linux常用操作命令 命令的基本格式 命令的提示符 [root@localhost ...
- cookie的介绍和使用
一.什么是cookie 是由服务器端生成,发送给客户端(一般指浏览器),浏览器将cookie以键值对的形式保存到某个目录下的文本文件内.下次请求该网站时就把cookie发送回服务器.(cookie就是 ...
- Module Error (from ./node_modules/eslint-loader/index.js):解决办法
vue启动项目报如下错误: Failed to compile. ./src/components/Vcontent.vue Module Error (from ./node_modules/esl ...
- Java WebService _CXF、Xfire、AXIS2、AXIS1_四种发布方式(使用整理)
目录 1. CXF方式2. Xfire方式3. AXIS2方式4. AXIS1方式5. AXIS1客户端调用6. AXIS2客户端调用7. CXF客户端调用8. Web Service Client客 ...
- java读写Excel模板文件,应用于负载均衡多个服务器
首先,需要大家明白一点,对于多服务器就不能用导出文件用a标签访问链接方式去导出excel文件了,原因相信大家也明白,可能也做过尝试. 现在开始第一步:get请求,productPath 为你的项目路径 ...
- 如何下载 Ubuntu 镜像文件?
Ubuntu,是一款基于 Debian Linux 的以桌面应用为主的操作系统,内容涵盖文字处理.电子邮件.软件开发工具和 Web 服务等,可供用户免费下载.使用和分享. 但是对于国内的用户来说如果直 ...
- Codeforces Round #651 (Div. 2)
感觉自己无可救药了. A题:找到小于等于n的两个不同的数的gcd最大是多少,显然是floort(n/2).设这两数是a * gcd, b * gcd然后gcd(a,b) = 1,那么gcd要尽量大,不 ...
- py4j.protocol.Py4JJavaError: An error occurred while calling z:org.apache.spark.api.python.PythonRDD.collectAndServe. : java.lang.IllegalArgumentException: Unsupported class file major version 55
今天小编用Python编写Spark程序报了如下异常: py4j.protocol.Py4JJavaError: An error occurred while calling z:org.apach ...