V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
phuslu
V2EX  ›  Python

gevent 写并发程序还是蛮顺手的。

  •  
  •   phuslu · 2012-08-25 16:43:56 +08:00 · 8412 次点击
    这是一个创建于 4277 天前的主题,其中的信息可能已经有所发展或是发生改变。
    打算写一个 google 北京的 hosts ip 枚举程序,稍微考虑了下,发现还是 gevent 实现方便。

    代码如下,跑起来很欢畅的~
    20 条回复    1970-01-01 08:00:00 +08:00
    INT21H
        1
    INT21H  
       2012-08-25 19:08:24 +08:00
    这个直接用 threading 就可以了吧?
    ratazzi
        2
    ratazzi  
       2012-08-25 20:36:45 +08:00
    @INT21H gevent 是更轻量的方式
    alsotang
        3
    alsotang  
       2012-08-25 22:06:49 +08:00
    @ratazzi 可以细说一下为何gevent更轻量级吗?
    ratazzi
        4
    ratazzi  
       2012-08-26 10:39:17 +08:00
    @alsotang 你搜一下 greenlet 就知道了,简单来说就是所谓的微线程,网上很多介绍的
    yaotian
        5
    yaotian  
       2012-08-26 21:29:53 +08:00
    @ratazzi 刚才看了一下,感觉不是微线程吧
    ratazzi
        6
    ratazzi  
       2012-08-26 22:39:01 +08:00
    @yaotian 也有称作协程的,现在貌似没有一个很权威的中文叫法吧,反正比线程轻量是一定的,不知道你认为是什么呢?
    ipconfiger
        7
    ipconfiger  
       2012-08-26 23:25:43 +08:00
    别用DNS一切都ok
    phuslu
        8
    phuslu  
    OP
       2012-08-26 23:33:45 +08:00
    改了一下,获取的 ip 更有效了。
    phuslu
        9
    phuslu  
    OP
       2012-08-26 23:34:18 +08:00
    @ipconfiger gevent 1.0 已经修复 DNS errno 66/67 的问题了。
    weiqiyiji
        10
    weiqiyiji  
       2012-08-27 10:13:59 +08:00
    我一般用gevent只patch ssl和socket,其他的都不patch
    phuslu
        11
    phuslu  
    OP
       2012-10-23 17:13:02 +08:00
    改了一下, 不止搜索证书为 *.google.com 了, 只要是 google.com 的都输出了.
    tonyseek
        12
    tonyseek  
       2012-10-24 10:08:20 +08:00
    `except ... pass` 看着非常不舒服
    clino
        13
    clino  
       2012-10-24 14:14:05 +08:00
    枚举出来的 ip 也都不能用呀...
    phuslu
        14
    phuslu  
    OP
       2012-10-24 14:24:12 +08:00
    @clino 呃, 不能用是指?
    clino
        15
    clino  
       2012-10-24 14:48:55 +08:00
    @phuslu 用在 /etc/hosts 里不行啊,直接用 http://ip 也连不上呀
    phuslu
        16
    phuslu  
    OP
       2012-10-24 14:52:52 +08:00
    @clino 嗯, 可能是你的网络环境(ISP?)的问题, wget http://ip 可以用吗?
    clino
        17
    clino  
       2012-10-24 20:49:41 +08:00
    @phuslu 汗,我在家想试试看,结果就完全没有 ip 出来,可能你设的这个网段已经屏蔽光了
    phuslu
        18
    phuslu  
    OP
       2012-10-24 21:35:28 +08:00
    @clino 换成 46.x 47.x 48.x 等网段试下呢
    cmsee
        19
    cmsee  
       2012-11-06 20:01:57 +08:00
    203.208.47.2
    203.208.47.4
    203.208.47.8
    203.208.47.1
    203.208.47.22
    203.208.47.28
    203.208.47.33
    203.208.47.68
    203.208.47.32
    203.208.47.23
    203.208.47.25
    203.208.47.20
    203.208.47.5
    203.208.47.29
    203.208.47.37
    203.208.47.66
    203.208.47.133
    203.208.47.136
    203.208.47.146
    203.208.47.31
    203.208.47.6
    203.208.47.17
    203.208.47.19
    203.208.47.159
    203.208.47.130


    203.208.46.16
    203.208.46.23
    203.208.46.24
    203.208.46.30
    203.208.46.32
    203.208.46.27
    203.208.46.129
    203.208.46.33
    203.208.46.128
    203.208.46.28
    203.208.46.20
    203.208.46.131
    203.208.46.34
    203.208.46.7
    203.208.46.198
    203.208.46.200
    203.208.46.201
    203.208.46.209
    203.208.46.243
    203.208.46.152
    203.208.46.214
    203.208.46.246
    203.208.46.241
    203.208.46.210
    203.208.46.197
    203.208.46.225
    203.208.46.194
    203.208.46.242
    203.208.46.199
    203.208.46.208
    203.208.46.213
    203.208.46.245
    203.208.46.224
    203.208.46.229
    203.208.46.25
    stary
        20
    stary  
       2013-02-17 20:35:46 +08:00
    大哥,这个不能用了restart,Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
    Type "copyright", "credits" or "license()" for more information.
    >>> ================================ RESTART ================================
    >>>

    >>> ================================ RESTART ================================
    >>> ,如何处理?多谢!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1110 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 19:01 · PVG 03:01 · LAX 12:01 · JFK 15:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.