Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #39667
    Peter Queen
    Participant

    Hello,

    After the lesson MAC changer I was practicing and I try to code the setting of wireless adapter in monitor mode. If I run it I get the error bufsize must be an integer.

    Can you help?
    Thanks

    #!/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 to monitor mode")
        (options, arguments) = parser.parse_args()
        if not options.interface:
            parser.error("[-] Please specify an interface, use --help for info")
        return options
    
    def monitor_mode(interface):
        print("Setting {} to monitor mode".format(interface))
        subprocess.call("ifconfig", interface, "down")
        subprocess.call("iwconfig", interface, "mode", "monitor")
        subprocess.call("ifconfig", interface, "up")
    
    options = get_arguments()
    monitor_mode(options.interface)
    #39736
    Diego PérezDiego Pérez
    Moderator

    Hi Simo!
    Can you share a screenshot of the error so I can see the full traceback?

    Let me know.
    Diego

    #39753
    Peter Queen
    Participant

    .

    #39763
    Peter Queen
    Participant

    file:///root/Pictures/Screenshot%20from%202020-06-11%2006-18-59.png

    #39765
    Peter Queen
    Participant

    root@kali:~/PycharmProjects/mac_changer# ls
    mac_changer.py set_monitor_mode.py venv
    root@kali:~/PycharmProjects/mac_changer# python set_monitor_mode.py
    Usage: set_monitor_mode.py [options]

    set_monitor_mode.py: error: [-] Please specify an interface, use –help for info
    root@kali:~/PycharmProjects/mac_changer# python set_monitor_mode.py -i wlan0
    Setting wlan0 to monitor mode
    Traceback (most recent call last):
    File “set_monitor_mode.py”, line 20, in <module>
    monitor_mode(options.interface)
    File “set_monitor_mode.py”, line 14, in monitor_mode
    subprocess.call(“ifconfig”, interface, “down”)
    File “/usr/lib/python2.7/subprocess.py”, line 172, in call
    return Popen(*popenargs, **kwargs).wait()
    File “/usr/lib/python2.7/subprocess.py”, line 343, in __init__
    raise TypeError(“bufsize must be an integer”)
    TypeError: bufsize must be an integer

    #39840
    Diego PérezDiego Pérez
    Moderator

    Hi Simo!

    If you want to use that synthax with subprocess you have to use square brackets as well. Like:
    subprocess.call([“ifconfig”, interface, “down”])

    Let me know how it goes!
    Diego

    #39856
    Peter Queen
    Participant

    Thanks Diego,

    It works perfectly!

    #39908
    Diego PérezDiego Pérez
    Moderator

    Hi Simo!

    Cool you got it!
    Diego

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.