NameError : name 'ip' is not defined - networking

after installing scapy in windows when I run the "scapy" command from command line to check if scapy is installed succesfully
it gives the following lines:
welcome to Scapy(2.1.1-dev)
>>>ip
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'ip' is not defined
how to fix this error?

Try.. doing this .. this would create a IP object and print it
>>>> print IP()
Or else populating IP options is explained in detail here: http://allievi.sssup.it/techblog/?p=631
>>> ip=IP(src="1.1.1.1", dst="8.8.8.8", options=IPOption('\x83\x03\x10'))

Related

One very strange os.getcwd - Yes the directory exists

Let me just jump straight in because I'm feeling kind of strange at the moment.
mkdir /var/tmp/myuser
cd /var/tmp/myuser
python
>>> import os
>>> os.getcwd()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno2] No such file or directory
>>> exit()
pwd
/var/tmp/myuser
There's no magic the directory is there, I have full access. How should I troubleshoot an issue like this?
Could you try executing os.chdir(path to your current directory) and then os.getcwd()?

NameError: name 'error' is not defined

So I was making a cheat program for a game using scapy, and when I ran it in visual studios it worked fine, but when I say in cmd
python myprogram.py
It says:
Traceback (most recent call last):
File "ScapyTest.py", line 135, in <module>
sniff(prn=action)
File "C:\Program Files\Python36\lib\site-packages\scapy\sendrecv.py", line
592, in sniff
sel = select([s],[],[],remain)
File "C:\Program Files\Python36\lib\site-packages\scapy\supersocket.py",
line 38, in fileno
return self.ins.fileno()
File "C:\Program Files\Python36\lib\site-packages\scapy\arch\pcapdnet.py",
line 232, in fileno
error("Cannot get selectable PCAP fd on Windows")
NameError: name 'error' is not defined
Im unsure if it literally means it doesnt know what an error is, or if there is some logical reason behind it not knowing what an error is. It is something with sniff but im not sure what. There are also no errors in my code so I dont know why its saying this
This looks like an old bug. You should get the current development version (from the official repository, install it and try again.

How to add a custom parser to logster?

I want to track the HTTP response codes returned by my nginx web-server, using logster.
1) I found and installed logster. I also pip-installed pygtail, which is required for logster.
https://github.com/etsy/logster
2) I found a python script that parses nginx access_log and placed it in the parsers subdir.
https://github.com/metabrainz/logster/blob/master/musicbrainz/logster/NginxStatus.py
...but when I run the logster command, I get a python exception:
Traceback (most recent call last):
File "/usr/local/bin/logster", line 5, in <module>
pkg_resources.run_script('logster==0.0.1', 'logster')
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 505, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1245, in run_script
execfile(script_filename, namespace, namespace)
File "/usr/local/lib/python2.7/dist-packages/logster-0.0.1-py2.7.egg/EGG-INFO/scripts/logster", line 449, in <module>
main()
File "/usr/local/lib/python2.7/dist-packages/logster-0.0.1-py2.7.egg/EGG-INFO/scripts/logster", line 380, in main
module = __import__(module_name, globals(), locals(), [parser_name])
ImportError: No module named NginxStatus1
````
What am I doing wrong?
The exception error was rather misleading: the file was placed in the right place (the parsers subdir), but - as it turns out- logster must be re-setup after a new parser is added (this isn't documented, unfortunately). so just run:
sudo python setup.py install
in the logster directory and things should start working correctly.

Python3 decode doesn't work on mac

I wrote this code:
'\xe4\xf6\xfc'.decode('latin1')
but I got this:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'decode'
I am using python 3.4 and I am using python on mac.
Because the string type does not support the .decode() method in Python 3. Simply prefix your string with b, which turns it into the bytes type:
>>> b'\xe4\xf6\xfc'.decode('latin1')
'äöü'

cx_freeze error with pyodbc

if you have a simple program name pyodbcTest.py
import pyodbc
print "pass"
and then use cx_freeze to compile it
cxfreeze --targe-dir=cxTest pyodbcTest.py
and then run that program it throws the following error.
C:\temp\pythonWork\cxTest>pyodbcTest.exe
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec code in m.__dict__
File "pyodbcTest.py", line 1, in <module>
RuntimeError: Unable to import decimal
Any ideas?
I had to add the option --include-module decimal to solve the problem. Not sure why it could not find that one on its own during the freeze process, but its working now

Resources