• Home
  • Hacking & Security
    • Network Hacking
    • Web Hacking
    • Social Engineering
    • Kali Linux
    Submit An Article
  • Courses
    • All Courses
    • Bundles
    • Masterclass
    • VIP Membership
    • FAQ

    Popular Courses

  • Shop
  • Competition
  • Services
    Penetration Testing
    Consulting
    Code Review
    One on one Training
    Online Courses
    VPN
  • Blog
      • Cart

    VIP Membership Masterclass
    Got a question?
    [email protected]
    RegisterLogin
    zSecurity
    • Home
    • Hacking & Security
      • Network Hacking
      • Web Hacking
      • Social Engineering
      • Kali Linux
      Submit An Article
    • Courses
      • All Courses
      • Bundles
      • Masterclass
      • VIP Membership
      • FAQ

      Popular Courses

    • Shop
    • Competition
    • Services
      Penetration Testing
      Consulting
      Code Review
      One on one Training
      Online Courses
      VPN
    • Blog
        • Cart

      Reply To: phython code not working

      June 13, 2021 at 4:09 pm #55725
      pranetkul
      Participant
      #!/usr/bin/env python
      
      import re
      import subprocess
      import optparse
      
      def get_args():
          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) = get_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"])
      
      def get_current_mac(interface):
          ifconfig_result = subprocess.check_output("ifconfig", interface)
          print(ifconfig_result)
          mac_address_search_result = re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w", str(ifconfig_result))
          if mac_address_search_result:
              return mac_address_search_result.group(0)
          else:
              print("[-] Could not read MAC address.")
      
      options = get_args()
      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")
      

      Categories

      • Cryptography
      • Cryptography
      • CTF
      • Forensics
      • Hacking & Security
      • Hardware
      • IOT
      • Kali Linux
      • Network Hacking
      • News
      • OSINT
      • Post Exploitation
      • Post Exploitation
      • Privacy
      • Programming
      • Security
      • Social Engineering
      • Uncategorized
      • Web Hacking

      Popular Posts

      Got a Blank Screen After Importing Kali in Virtual Box ? Here’s How To Fix It
      25Jan2018

      Connect with us

      • Facebook
      • Twitter
      • LinkedIn
      • Instagram
      • Youtube

      “Everything related to ethical hacking

      & cyber security in one place.”

      Quick Links

      • Home
      • About Us
      • Hacking & Security
      • Download Custom Kali
      • Contact
      • FAQ

      Services

      • Penetration Testing
      • Consulting
      • Code Review
      • One on one training
      • VPN
      • VIP Membership

      Company

      • About Us
      • Contact
      • Vulnerability Disclosure

      Support

      • FAQ
      • Forums

      Copyright © 2021 zSecurity Ltd. All rights reserved.

      • Privacy
      • Refunds
      • Terms

      Contribute

      Share your knowledge with the world

      SUBMIT AN ARTICLE

      Login with your site account

      Lost your password?

      Not a member yet? Register now

      Register a new account


      Are you a member? Login now

      Learn more Hacking!

      While waiting for the download, why not follow us on media? We regularly post hacking tutorials and articles


      We are using cookies to give you the best experience on our website. This includes but is not limited to:

      • Storing your settings and preferences.
      • Remember your access information
      • Track website performance and make our website more relevant to you.

      You can find out more about which cookies we are using or switch them off in settings.

      Privacy Overview

      This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

      Strictly Necessary Cookies

      Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.

      3rd Party Cookies

      This website uses Google Analytics and Linkedin to collect anonymous information such as the number of visitors to the site, and the most popular pages.

      Keeping this cookies enabled helps us to improve our website.

      Please enable Strictly Necessary Cookies first so that we can save your preferences!

      Powered by  GDPR Cookie Compliance