sniffer in python

billiejoex billiejoex at fastwebnet.it
Tue Aug 16 05:52:46 EDT 2005


Thanks for your help. Like you suggested I converted the integer value in a
string one by using the repr() funtion applied on the print:

print '%d \n %s' %(count, repr(iface))

The program now permit me to select the interface. The output is in a
strange hex-similar form:

C:\Python24>test.py
0
 u'\u445c\u7665\u6369\u5c65\u504e\u5f46\u6547\u656e\u6972\u4e63\u6964\u5773\u6e61\u6441\u7061\u6574r\u445c\u7665\u6369\u5c65\u504e\u5f46\u317b\u4534\u3544\u3642\u2d31\u3030\u3942\u342d\u4441\u2d39\u3341\u4345\u382d\u3033\u3246\u3938\u3241\u4531\u7d44\u5c00\u6544\u6976\u6563\u4e5c\u4650\u7b5f\u3541\u3630\u3934\u3434\u452d\u4230\u2d37\u3634\u3239\u382d\u4237\u2d35\u4630\u3133\u4244\u3933\u3532\u3943}\u445c\u7665\u6369\u5c65\u504e\u5f46\u377b\u4337\u3644\u3034\u2d31\u3841\u3143\u342d\u3743\u2d43\u3241\u4633\u432d\u3731\u3037\u3538\u3234\u4538\u7d34'1 u'\u6547\u656e\u6972\u2063\u644e\u7369\u6157\u206e\u6461\u7061\u6574r\u4d56\u6177\u6572\u5620\u7269\u7574\u6c61\u4520\u6874\u7265\u656e\u2074\u6441\u7061\u6574r\u4d56\u6177\u6572\u5620\u7269\u7574\u6c61\u4520\u6874\u7265\u656e\u2074\u6441\u7061\u6574r\u564e\u4449\u4149\u6e20\u6f46\u6372\u2065\u434d\u2050\u654e\u7774\u726f\u696b\u676e\u4120\u6164\u7470\u7265\u4420\u6972\u6576\u2072\u4d28\u6369\u6f72\u6f73\u7466\u7327\u5020\u6361\u656b\u2074\u6353\u6568\u7564\u656c\u2972 'Please select an interface: 0When I select the interface (0 or 1) I encounter an encoding error:Traceback (most recent call last):  File "C:\Python24\test.py", line 108, in ?    main(filter)  File "C:\Python24\test.py", line 92, in main    p = open_live(dev, 1500, 0, 100)UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-15:ordinal not in range(128)- How con I resolve this encoding problem?- How can I display the interface names in a 'human' form?Best regardsbillie> Helping you learn to troubleshoot from tracebacks: look at the linepreceding the failing call.  Can you guess anything about what in that linemight be causing an encode() call?  The count variable is, presumably, justan integer, so %i wouldn't like have to do more than convert it to a string.%s, however, asks for "iface" to be turned into a string... if it were notalready a string (i.e. it's a unicode?) it would have to be encoded.  Whatdoes iface contain and where did it come from?  Can you make it be just astring?  Does that change or fix anything?>> -Peter




More information about the Python-list mailing list