I installed scapy for python3.4 as suggested to me in previous post (link: https://github.com/phaethon/scapy).
I tried to run this very simple code to show all the wifi networks detected by the program:
#!/usr/bin/python3.4
from scapy import *
ap_list = []
def PacketHandler(pkt) :
if pkt.haslayer(Dot11) :
if pkt.type == 0 and pkt.subtype == 8 :
if pkt.addr2 not in ap_list :
ap_list.append(pkt.addr2)
print ("AP MAC: {} with SSID: {} ".format(pkt.addr2, pkt.info))
sniff(iface="mon0", prn = PacketHandler)
I get the following error when I run the script:
python3.4 test_scapy.py
Traceback (most recent call last):
File "test_scapy.py", line 16, in <module>
sniff(iface="mon0", prn = PacketHandler)
NameError: name 'sniff' is not defined
It seems to me that the function 'sniff' does not work just as in the previous versions, I tried to find the problem without success. If someone knows how to make the function 'sniff' work on this version it would help me a lot.
Thank you for your time.
Related
I am trying to deploy a ovf image in vcenter using the code in below link:
[https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/deploy_ovf.py][1]
python vm_deploy.py -s ‘vcneter_url’ -u ‘username’ -p ‘password’ -v ‘.vmdk path’ -f ‘.ovf path’
But it is failing with below traceback:
Traceback (most recent call last):
File "orig.py", line 218, in <module>
exit(main())
File "orig.py", line 185, in main
objs = get_objects(si, args)
File "orig.py", line 150, in get_objects
resource_pool_obj = cluster_obj.resourcePool
AttributeError: 'vim.Folder' object has no attribute 'resourcePool'
Im not able to get much help on this error online other than below link:
[https://github.com/vmware/pyvmomi-community-samples/issues/201][1]
I can see dir(cluster_obj) has no resourcePool in it but not sure how to get this working.
This script work only if you have manually created a resource pool in your architecture.
However, with a little modification you can target the default resourcePool of a specific Host.
Replace, in get_objects function, this (~line 140) :
# Get cluster object.
cluster_list = datacenter_obj.hostFolder.childEntity
if args.cluster_name:
cluster_obj = get_obj_in_list(args.cluster_name, cluster_list)
elif len(cluster_list) > 0:
cluster_obj = cluster_list[0]
else:
print "No clusters found in DC (%s)." % datacenter_obj.name
hosts = datacenter_obj.hostFolder.childEntity
resource_pool = hosts[0].resourcePool
# Generate resource pool.
resource_pool_obj = cluster_obj.resourcePool
By this :
for computeResource in datacenter_obj.hostFolder.childEntity :
if computeResource.name == 'ip or hostname here':
resource_pool = computeResource.resourcePool
break
The datacenter_obj is given, in the script that you gave, with something lik this :
datacenter_obj = si.content.rootFolder.childEntity[0]
0 is the first Datacenter found.
I hope it will help you, even if the answer comes a little late
I am trying to move data (a dint specifically but my example is a BOOL) from the plc to python to be used as a variable to display a picture. The issue is, if I use pycomm, I am getting an error in Windows Powershell. I feel this is a very simple error from a basic python mistake rather than a pycomm issue but I am not informed enough to tell.
SysInfo:
configparser==3.5.0
cpppo==3.9.7
greenery==2.1
ipaddress==1.0.18
pycomm==1.0.8
pyreadline==2.1
pytz==2017.2
python==2.7.13
Code I am using:
from pycomm.ab_comm.clx import Driver as ClxDriver
import logging
if __name__ == '__main__':
c = ClxDriver()
if c.open('IPADDRESSHERE'):
print(c.read_tag(['new_Bool']))
c.close()
Which is just a stripped down version of one of the examples on github https://github.com/ruscito/pycomm
This is the result from running powershell:
PS C:\Users\Tom\Documents\PythonProjects> python pycomm2.py
Traceback (most recent call last):
File "pycomm2.py", line 10, in
print(c.read_tag(['new_Bool']))
File "C:\Python27\lib\site-packages\pycomm\ab_comm\clx.py", line 359, in read_tag
self.logger.warning(self._status)
AttributeError: 'Driver' object has no attribute 'logger'
PS C:\Users\Tom\Documents\PythonProjects>
I have looked for this AttributeError and tried to find a solution, but I think the solutions I have found are over my head. If I have failed to provide some details in order for this question to make sense please let me know.
Edit:
from pycomm.ab_comm.clx import Driver as ClxDriver
import logging
if __name__ == '__main__':
logging.basicConfig(
filename="ClxDriver.log",
format="%(levelname)-10s %(asctime)s %(message)s",
level=logging.DEBUG
)
c = ClxDriver()
if c.open('IPADRESSHERE'):
print(c.read_tag(['new_Bool']))
c.close()
Yields the same attribute error.
PS C:\Users\Tom\Documents\PythonProjects> python pycommtest.py
Traceback (most recent call last):
File "pycommtest.py", line 15, in
print(c.read_tag(['new_Bool']))
File "C:\Python27\lib\site-packages\pycomm\ab_comm\clx.py", line 359, in read_tag
self.logger.warning(self._status)
AttributeError: 'Driver' object has no attribute 'logger'
PS C:\Users\Tom\Documents\PythonProjects>
I was able to read a value, but not with pycomm. Using CPPPO, I was able to continuously update a variable as needed. This may not answer the question of what was wrong with my old code, but it is my work around in case someone from the future has to do the same thing. Credit to user Liverpool_chris and the abyss of Reddit.
https://www.reddit.com/r/PLC/comments/5x3y5z/python_cpppo_library_writing_to_tag_in_plc/
from cpppo.server.enip.get_attribute import proxy_simple
import time
host = "IPHERE"
while True:
x, = proxy_simple(host).read(( "CPID"))
print x
time.sleep(5)
I am working on a Raspberry Pi 3 and I am trying to visualize some values of sensors on Munin. I am using Python in order to execute scripts on Munin.
I found a script to test and I am trying to execute it but I got the following error :
Traceback (most recent call last):
File "cpu_field", line 23, in
munin.main()
AttributeError: 'module' object has no attribute
'main'
This is the script : https://github.com/CooledCoffee/python-munin/
Of course, I added at the beginning :
!/usr/bin/env python
But, what I didn't understand is that others scripts are working like this one :
https://gist.github.com/tomoconnor/813813
Would be nice if you could put the code in the question as well.
Anyways. The python-munin you use is entirely different and provides no main() function (as it called in line 23). Names for python modules are not protected and
'munin' is a obvious choice used by more than one developer.
The first script should run with the module you get with
pip install python-munin
The other script uses this python-munin module and you probably get it directly from the git repository. They are not compatible.
So, this is the code I am using :
> #!/usr/bin/env python
>
> import munin
>
> category = 'system' fields = [
> 'load1',
> 'load5',
> 'load15', ] vlabel = 'load'
>
> def values():
> with open('/proc/loadavg') as f:
> data = f.read()
> load1, load5, load15 = [float(s) for s in data.split()[:3]]
> return {
> 'load1': load1,
> 'load5': load5,
> 'load15': load15,
> }
>
> if __name__ == '__main__':
> munin.main()
This is the answer I got with sudo python xxx, I got the same answer with sudo munin-run xxx :
pi#dex:/etc/munin/plugins $ sudo python first
Traceback (most recent call last):
File "first", line 24, in <module>
munin.main()
AttributeError: 'module' object has no attribute 'main'
I thin you are right because when I installed munin with
pip install python-munin
it worked. But, then I installed this python-munin module and it didn't work anymore. I removed the folder python-munin but I still got the same error.
How can I remove properly the previous folder ?
I am trying to generate a list of product/vendor IDs with Pyusb and I am having trouble. I found a suggestion online from orangecoat.
import sys
import usb.core
import usb.util
dev = usb.core.find(find_all=True)
if dev is None:
raise ValueError('Device not found')
cfg = dev.get_active_configuration()
Python gives the following error though:
Traceback (most recent call last):
File "C:/Python27/usbfinddevices.py", line 10, in <module>
cfg = dev.get_active_configuration()
AttributeError: 'generator' object has no attribute 'get_active_configuration'
Could someone help me understand why I am getting this error?
Thank you
You're almost there, but you need to iterate through your dev object which is a generator.
dev = usb.core.find(find_all=True)
for d in dev:
print usb.util.get_string(d,128,d.iManufacturer)
print usb.util.get_string(d,128,d.iProduct)
print (d.idProduct,d.idVendor)
Save this script
test.py
import usb.core
import usb.util
dev = usb.core.find(find_all=True)
# get next item from the generator
d = dev.next()
print d.get_active_configuration()
then, run this
sudo python test.py
On Windows with Python 3 you need to change line d = dev.next() to d = next(dev) (as pointed out in the comments by #gabin)
I have a python script like this:
#!/usr/bin/env python
from scapy.all import *
from ospf import *
def ourSend(packet):
sendp(packet,iface='eth1')
host1='10.0.3.2'
advr_routers='10.0.8.7'
host2='10.0.2.2'
sequence=0x80000918
link2host1 = OSPF_Link(id=host1,data='10.0.3.1',type=2,metric=1)
link2host2 = OSPF_Link(id=host2,data='10.0.2.2',type=2,metric=1)
link2victim = OSPF_Link(id="192.168.200.20",data="255.255.255.255",type=3,metric=1)
IPlayer=IP(src='10.0.1.2',dst='224.0.0.5')
OSPFHdr=OSPF_Hdr(src='10.0.6.1')
rogueLsa=Ether()/IPlayer/OSPFHdr/OSPF_LSUpd(lsacount=1,lsalist=[OSPF_Router_LSA(options=0x22,id='10.0.3.1',adrouter=advr_routers,seq=sequence,\
linkcount=3,linklist=[link2victim,link2host1,link2host2])])
ourSend(rogueLsa)
When I run it it has an scapy error.. So I resolved it with git pyrt...
now when I want to run the python script I have other error:
$ python scipt.py
WARNING: No route found for IPv6 destination :: (no default route?)
Traceback (most recent call last):
File "s.py", line 19, in <module>
link2host1 = OSPF_Link(id=host1,data='10.0.3.1',type=2,metric=1)
NameError: name 'OSPF_Link' is not defined
Thank you
I Should separately get ospf.py again and run my script.
This is what I tried and worked...
When you git pyrt The module OSPF_Link can't be added. SO I used the ospf.py again and problem is solved now....