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)的更多相关文章

  1. Python Ethical Hacking - MAC Address & How to Change(3)

    SIMPLE ALGORITHM Goal  -> Check if MAC address was changed. Steps: 1. Execute and read ifconfig. ...

  2. Python Ethical Hacking - MAC Address & How to Change(1)

    MAC ADDRESS Media Access Control Permanent Physical Unique Assigned by manufacturer WHY CHANGE THE M ...

  3. Python Ethical Hacking - ARP Spoofing

    Typical Network ARP Spoofing Why ARP Spoofing is possible: 1. Clients accept responses even if they ...

  4. Python Ethical Hacking - NETWORK_SCANNER(1)

    NETWORK_SCANNER Discover all devices on the network. Display their IP address. Display their MAC add ...

  5. Python Ethical Hacking - NETWORK_SCANNER(2)

    DICTIONARIES Similar to lists but use key instead of an index. LISTS List of values/elements, all ca ...

  6. Python Ethical Hacking - BeEF Framework(1)

    Browser Exploitation Framework. Allows us to launch a number of attacks on a hooked target. Targets ...

  7. Python Ethical Hacking - WEB PENETRATION TESTING(1)

    WHAT IS A WEBSITE Computer with OS and some servers. Apache, MySQL ...etc. Cotains web application. ...

  8. Python Ethical Hacking - BACKDOORS(8)

    Cross-platform hacking All programs we wrote are pure python programs They do not rely on OS-specifi ...

  9. Python Ethical Hacking - BACKDOORS(7)

    Handling Errors: If the client or server crashes, the connection will be lost. Backdoor crashes if: ...

随机推荐

  1. 【JMeter_15】JMeter逻辑控制器__仅一次控制器<Once Only Controller>

    仅一次控制器<Once Only Controller> 业务逻辑: 在每个线程内,该控制器下的内容只会被执行一遍,无论循环多少次,都只执行一遍.<嵌套在循环控制器之内时是个例外,每 ...

  2. JSR133提案-修复Java内存模型

    目录 1. 什么是内存模型? 2. JSR 133是关于什么的? 3. 再谈指令重排序 4.同步都做了什么? 5. final字段在旧的内存模型中为什么可以改变? 6."初始化安全" ...

  3. AOF文件的写入与同步

    在 Redis 中客户端向服务器发送相关写命令请求,这时服务器中有个用于处理这些命令的事件循环进程,对这些命令进行处理,并将相关信息处理的结果反馈给客户端,如:"OK",等.同时, ...

  4. 谈谈我对 Flutter 未来发展 和 “嵌套地狱” 的浅显看法

    Flutter 未来发展 提到 Flutter 就不得不提到 Fuchsia 系统,这是一个尚未正式发布的操作的系统,引用 Android 和 Chrome 的高级副总裁 Hiroshi Lockhe ...

  5. 上位机面试必备——TCP通信灵魂二十问【下】

    上篇文章跟大家介绍了TCP通信常见的前10个面试题,没看过的小伙伴可以点击下方链接进行查看: 上位机面试必备——TCP通信灵魂二十问[上] 今天就后面的10个面试题接着做下说明:欢迎关注[dotNet ...

  6. Code Walkthroughs Table API

    上级:https://www.cnblogs.com/hackerxiaoyon/p/12747387.html Table API Table api 有批量的api和流实时的api.通常很容易进行 ...

  7. 入门大数据---Spark车辆监控项目

    一.项目简介 这是一个车辆监控项目.主要实现了三个功能: 1.计算每一个区域车流量最多的前3条道路. 2.计算道路转换率 3.实时统计道路拥堵情况(当前时间,卡口编号,车辆总数,速度总数,平均速度) ...

  8. TCP协议粘包问题详解

    TCP协议粘包问题详解 前言 在本章节中,我们将探讨TCP协议基于流式传输的最大一个问题,即粘包问题.本章主要介绍TCP粘包的原理与其三种解决粘包的方案.并且还会介绍为什么UDP协议不会产生粘包. 基 ...

  9. npm和webpack

    npm是前端开发中常用的一种工具,对于普通开发者来说,便于管理依赖. 往大了说,便于共享代码.写完代码,使用npm发布以后,然后别人用npm可以方便地共享到你的代码. npm的使用: mac环境下的安 ...

  10. 一天学习一点之如何安装nodejs

    如果没有安装git,先使用命令apt-get install git,然后按以下步骤安装即可 Install the dependencies:sudo apt-get install g++ cur ...