Running a script

Hey guys I need help, I am currently trying to run this script that im learning off of youtube. 10. Write Python Jammer to Jam WiFi networks using python | Ethical Hacking using python - YouTube

So basically im getting this error every time I run
$ python2.7 example.py
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
root@thr33sixnine:/home/thr33sixnine369/Documents# python2.7 example.py
Traceback (most recent call last):
File “example.py”, line 3, in
import wireless
File “/usr/local/lib/python2.7/dist-packages/wireless/init.py”, line 2, in
from wireless.Wireless import Wireless
File “/usr/local/lib/python2.7/dist-packages/wireless/Wireless.py”, line 4, in
from packaging import version
File “/usr/local/lib/python2.7/dist-packages/packaging/version.py”, line 42
def parse(version: str) → Union[“LegacyVersion”, “Version”]:
^
SyntaxError: invalid syntax
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

I’v,e re-downloaded Ubuntu all over again to try and get around this. But it didnt work Obvousily. I’m fairly new at all of this one of the first things were not having the imports that I was trying to import. So i downloaded them using pip. Then even though they were downloaded they still werent being found. Until I realized that they werent in the right folder and now I had to get access then figure out where they needed to be in. I finally got all that sorted out. Now i have this problem and 5 hours later and i still cant figure it out.

THIS IS THE SCRIPT IM TRYING TO RUN…

import wireless
from wifi import Cell
from scapy.all import *

wifi1 = wireless.Wireless()
interface = wifi1.interface()

all_wifi_networks = Cell.all(interface)

print all_wifi_networks

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////If anyone can point me in the right direction or at least break it down to me. THANKS

The wireless package depends on the packaging package, which does not support python2.7. Try rewriting your script for python3.

1 Like

You cannot properly use or install this package for Python 2.7. The code is written for Python 3 and must be installed for a 3.x version of Python. This means you must have such a Python on your system first, reinstall those libraries for that Python, write your code using valid Python 3.x syntax (for example, this means that print is a function now), and use that Python to run the code.

Python 2.7 is not supported, even for security bugfixes. This has been the case since January 1, 2020. (And that’s with it being on an extended schedule to allow people to migrate! It was originally released in July of 2010.)

Do not attempt to remove any version of Python that came with your computer. You can seriously damage your operating system by doing so. However, if your computer came with Python 2.7, you should strongly consider upgrading your operating system. What version of Ubuntu are you using? Modern distributions should not require 2.7. For example, I am running Mint 20.3 (released Jan 2022) and it came with 3.8 (which will be officially supported and maintained until Oct 2024).

If the problem you are having is “I am trying to use pip to install the packages, but I have multiple versions of Python on the computer and it is installing to the wrong one”: use the Pip that comes with the version of Python you want to use. To make sure of this, use a command that will run that Python (hint: since we must use a 3.x version of Python, that command will definitely not look like python2.7), and pass the arguments -m pip, followed by the rest of the Pip arguments. This tells that specific version of Python to run its pip standard library module directly (each pip executable is basically a wrapper that does the same thing).

1 Like

Ok thanks I understood some what of what you told me except for “print” being a function.
I made these adjustments and I get this.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

import wireless
from wifi import Cell
from scapy.all import *

wifi1 = wireless.Wireless()
interface = wifi1.interface()

all_wifi_networks = Cell.all(interface)

#made this adjusment
print(all_wifi_networks) # was originally like this “print all_wifi_networks”

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Now i get this in return:
<map object at 0x7f1b85150760>

But in return im suppose to be getting:
Cell ssid=******* 0480

I suppose because of how I wrote out print and its function?

I am using python 3.10. Which is what originally came with ubuntu but i downloaded python 2.7 because of the video, I know you said that the script would change but how much does it really change?

The thing breaking your script for Python 2 was the type annotation
“:str”, which did not exist in Python 2. You’ve already adjusted for
print() being a function, so otherwise little will change.

Your code:

 all_wifi_networks = Cell.all(interface)
 #made this adjusment
 print(all_wifi_networks)   # was originally like this "print  all_wifi_networks"

Now i get this in return:

 <map object at 0x7f1b85150760>

But in return im suppose to be getting:

 Cell ssid=******* 0480

It seems likely that Call.all() is returning the result of a map()
call, probably converting network information to a sequence of special
objects describing each network.

In Python 2 map() returned a list. In Python 3 it returns an iterable
which yields the values. This is more memory efficient, and several
builtin functions which returned “complete” things like lists changed to
returning “lazy” things like iterables, which only produce the values as
requested.

You need to collect the values from the map object. Here’s an example:

 >>> m = map(str,[1,2,3])
 >>> m
 <map object at 0x10966fe80>
 >>> list(m)
 ['1', '2', '3']

Here I’m mapping a list if ints to strings. But map() just returns
me something which can to that. It’s iterable, so it’s perfect usable
in a for-loop etc. But to get the concrete values all collected I pass
it to list() to make a new list. That iterates for you to collect
those values.

You could also just iterate directly to print the values:

 >>> m = map(str,[1,2,3])
 >>> for a in m:
 ...     print(a)
 ...
 1
 2
 3

Cheers,
Cameron Simpson cs@cskk.id.au

Can you show me how you would add that to the code? Because I tried it and it gives me this error:

File “/home/thr33sixnine369/Documents/example.py”, line 14
>>> m = map(str,[1,2,3])
^^
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I played around with it but got nowhere. I also ran “print ({inteface})” and it gave me “wlo1”
which is my interface so in a way its working i think. I’m fairly new and am passionate about all this. I’ve been doing it for 1 year on and off but lately I’ve been going hard on learning.
this week from Monday i think i have a little over 15 hours just trying to learn. I’m saying all this to see if you can explain how to input the code you showed me into the code I’m trying to make

That >>> is the Python interactive prompt; you don’t want it. Just
use:

 m = map(str,[1,2,3])

This is what I get running this code:
import wireless
from wifi import Cell
from scapy.all import *

wifi1 = wireless.Wireless()
interface = wifi1.interface()

all_wifi_networks = Cell.all(interface)

print ({all_wifi_networks})
m = map(str,[1,2,3])
for a in m:
print(a)

1
2
3

root@thr33sixnine:/home/thr33sixnine369/Documents# python3.10 example.py
{<map object at 0x7f7a7ff90790>}
1
2
3

Like i said im learning and im sorry i dont mean to bother you.
I dont know if you saw the video that i posted up in the beginning, but essentialy im making some sort of wifi jammer. Unfortunately the guy in the video is using python2.7
So I see the challenge translating the code from python2.7 to python3.10. Especially for a beginner like me

This is what I get running this code:
[…]
all_wifi_networks = Cell.all(interface)
print ({all_wifi_networks})

This prints a set containing one item, all_wifi_networks. Just drop
the {} brackets.

m = map(str,[1,2,3])
for a in m:
print(a)

1
2
3

I had intended you to infer that you can print the contents of a map
object by iterating over it. So I’d hoped you’d write comething like
this in order to print the networks:

 for network in all_wifi_networks:
     print(network)

Note that a map object is an iterable (which lets you use it in the
for-loop, because a for-loop iterates over its argument), and it gets
consumed by the iteration. If you ran that loop a second time it would
print nothing because the map object is now empty.

To reuse it you need to store all the items, typicaly in a list:

 all_wifi_networks = list(all_wifi_networks)

This iterates over the initial all_wifi_networks map object, and
stored the results in a new list, which we then keep a reference to in
the all_wifi_networks variable (replacing our former reference to the
map object). Now you can run the for-loop more than once:

 for network in all_wifi_networks:
     print(network)
 for network in all_wifi_networks:
     print(network)

effectively, because iterating over a list does not empty the list.

Ok I have a lot of questions I know “Cell” came from “wifi”. Because we used “from wifi import Cell” but I dont understand how we know to use “Cell”. I get that we are assigning “all_wifi_networks” to “Cell.all(interface)” But how do we know that “Cell.all(interface)” is going to scan for all networks? Are their universal names that is used when coding like “interface”

You think you can help me get the “bssid”,“channel”,“quality”. I tried

for wifi in all_wifi_networks:
print ("Network Name (ssid) : ") +s wifi.ssid
print ("Network Address (bssid) : ") + wifi.address
print ("Network channel : ") + str(wifi.channel)
print ("Network Quality : ") + str(wifi.quality)

im getting a bunch of errors

I think i’d rather know the how your getting it then just getting the code which doesnt help much unless I know how your getting it.

Ok so I was able to get the bssid,quality,and channel but i cant get the name out in front of it. You know like:
Network Name (ssid) : myspectrum
All I get is:
myspectrum

I know its because Im not using print correctly but I’ve tried all i can think of.
This is how I’ve gotten it to print out what i want with out the names in front:

#/bin/bash/python3.10

import wireless
from wifi import Cell
from scapy.all import *

wifi1 = wireless.Wireless()
interface = wifi1.interface()

all_wifi_networks = Cell.all(interface)

all_wifi_networks = list(all_wifi_networks)

for network in all_wifi_networks:
print(network.ssid)
print(network.address)
print(network.channel)
print(network.quality)

You can pass more than one object to the print() function.

As an example:

print("SSID:",network.ssid)

yes i just figured it out using:

#/bin/bash/python3.10

import wireless
from wifi import Cell
from scapy.all import *

wifi1 = wireless.Wireless()
interface = wifi1.interface()

all_wifi_networks = Cell.all(interface)

all_wifi_networks = list(all_wifi_networks)

bssids =
for network in all_wifi_networks:
print("Network Name (ssid) : " + network.ssid)
print("Network Address (bssid) : " + network.address)
print("Network Channel : " + str(network.channel))
print("Network Quality : " + str(network.quality))
bssids.append(network.address)

Thank you so much

print("Network Name (ssid) : " + network.ssid)

You can also write this like this:

 print("Network Name (ssid) :", network.ssid)

The print() function puts a space between each argument for you (you
can override this separator with the sep= argument).

print("Network Channel : " + str(network.channel))

Also, print() calls str() on each of its arguments for you. Abovem
you’re calling str(network.channel) purely to convert it to a string
which you can then add to the prefix "Network Channel : ". If you do
this:

 print("Network Channel :", network.channel)

then print() does the str() for you, and inserts the space.

Cheers,
Cameron Simpson cs@cskk.id.au

Ok I have a lot of questions I know “Cell” came from “wifi”. Because we used “from wifi import Cell” but I dont understand how we know to use “Cell”. I get that we are assigning “all_wifi_networks” to “Cell.all(interface)” But how do we know that “Cell.all(interface)” is going to scan for all networks? Are their universal names that is used when coding like “interface”