技能等级:初学者
我想在python中添加一个库.延伸是轮子.
有人能说出安装车轮文件的逐步方法吗?
我试图在Scapy中编写一个简单的嗅探器,它只使用GET方法打印HTTP数据包.这是代码:
#!/usr/bin/python
from scapy.all import *
def http_header(packet):
http_packet=str(packet)
if http_packet.find('GET'):
print GET_print(packet)
print packet
def GET_print(packet1):
print "***************************************GET PACKET****************************************************"
print packet1
print "*****************************************************************************************************"
sniff(iface='eth0',prn=http_header)
Run Code Online (Sandbox Code Playgroud)
这是输出:
*****************************************************************************************************
None
T???
)?pEa??@@???h??#/??t
?}LGku???U
oTE??I(????9qi???S?????
XuW?F=???-?k=X:?
***************************************GET PACKET****************************************************
T???
)?pE???@@???h??#/??t
?LGku????
oTE??I?K??AH?*?e??>?v1#D?(mG5T?o????8?????????"?KT^?'?mB???]?????k>
?_x?X?????8V???w/?Z?=???N?À??\r?????)+}???l?c?9??j;???h??5?T?9H?/O??)??P
?Y?qf??%?_`??6x??5D?I3???O?
t??tpI#?????$IC??E??
?G?
J??????=?]??v????b5^|P??DK?)uq?2????w?
tB??????y=???n?i?r?.D6?kI?a???6iC???c'??0dPqED?4????[?[??hGh???~|Y/?>`\6yP Dq??T??M????f?;??????? gY???di?_x?8|
eo?p?xW9??=???v?Ye?}?T???y?^?C
-?_(?<?{????}???????r
$??J?k-?9????}??f?27??QK??`?GY?8??Sh???Y@8?E9?R??&a?/vk???6?DF`?/9?I?d( ??-??[A
??)pP??y\?j]???8?_???vf?b????I7???????+?P<_`
*****************************************************************************************************
Run Code Online (Sandbox Code Playgroud)
我期待的是:
GET / HTTP/1.1
Host: google.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20140722 Firefox/24.0 Iceweasel/24.7.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: PREF=ID=758a20b5fbd4eac9:U=2b2dedf6c84b001f:FF=0:TM=1412150291:LM=1415430021:S=Q-QemmrLqsSsEA9i; NID=67=mRdkPVhtImrOTLi5I1e5JM22J7g26jAcdiDEjj9C5q0H5jj0DWRX27hCM7gLJBeiowW-8omSv-1ycH595SW2InWX2n1JMMNh6b6ZrRsZ9zOCC2a-vstOQnBDSJu6K9LO
Connection: keep-alive …Run Code Online (Sandbox Code Playgroud) 即使我没有将线程设置为守护进程,一旦queue.join()完成和解除阻塞,程序是否应该退出?
#!/usr/bin/python
import Queue
import threading
import time
class workerthread(threading.Thread):
def __init__(self,queue):
threading.Thread.__init__(self)
self.queue=queue
def run(self):
print 'In Worker Class'
while True:
counter=self.queue.get()
print 'Going to Sleep'
time.sleep(counter)
print ' I am up!'
self.queue.task_done()
queue=Queue.Queue()
for i in range(10):
worker=workerthread(queue)
print 'Going to Thread!'
worker.daemon=True
worker.start()
for j in range(10):
queue.put(j)
queue.join()
Run Code Online (Sandbox Code Playgroud)
任何帮助将非常感谢!
我正在尝试以下代码:
#!/usr/bin/python
import multiprocessing
def f(name):
print 'hello', name
if __name__ == '__main__':
p = multiprocessing.Process(target=f, args=('bob',))
p.start()
p.join()
Run Code Online (Sandbox Code Playgroud)
我得到的输出是:
Traceback (most recent call last):
File "a.py", line 9, in <module>
p = multiprocessing.Process(target=f, args=('bob',))
AttributeError: 'module' object has no attribute 'Process'
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下命令在 kali linux(debian 派生发行版)上安装“python-pip”:
apt-get install python-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python-pip
Run Code Online (Sandbox Code Playgroud)
我遇到了以上错误。
有什么帮助吗?