V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Aug 25, 2012 · 9368 views
    This topic created in 4998 days ago, the information mentioned may be changed or developed.
    打算写一个 google 北京的 hosts ip 枚举程序,稍微考虑了下,发现还是 gevent 实现方便。

    代码如下,跑起来很欢畅的~
    20 replies    1970-01-01 08:00:00 +08:00
    INT21H
        1
    INT21H  
       Aug 25, 2012
    这个直接用 threading 就可以了吧?
    ratazzi
        2
    ratazzi  
       Aug 25, 2012
    @INT21H gevent 是更轻量的方式
    alsotang
        3
    alsotang  
       Aug 25, 2012
    @ratazzi 可以细说一下为何gevent更轻量级吗?
    ratazzi
        4
    ratazzi  
       Aug 26, 2012
    @alsotang 你搜一下 greenlet 就知道了,简单来说就是所谓的微线程,网上很多介绍的
    yaotian
        5
    yaotian  
       Aug 26, 2012
    @ratazzi 刚才看了一下,感觉不是微线程吧
    ratazzi
        6
    ratazzi  
       Aug 26, 2012
    @yaotian 也有称作协程的,现在貌似没有一个很权威的中文叫法吧,反正比线程轻量是一定的,不知道你认为是什么呢?
    ipconfiger
        7
    ipconfiger  
       Aug 26, 2012
    别用DNS一切都ok
    phuslu
        8
    phuslu  
    OP
       Aug 26, 2012
    改了一下,获取的 ip 更有效了。
    phuslu
        9
    phuslu  
    OP
       Aug 26, 2012
    @ipconfiger gevent 1.0 已经修复 DNS errno 66/67 的问题了。
    weiqiyiji
        10
    weiqiyiji  
       Aug 27, 2012
    我一般用gevent只patch ssl和socket,其他的都不patch
    phuslu
        11
    phuslu  
    OP
       Oct 23, 2012
    改了一下, 不止搜索证书为 *.google.com 了, 只要是 google.com 的都输出了.
    tonyseek
        12
    tonyseek  
       Oct 24, 2012
    `except ... pass` 看着非常不舒服
    clino
        13
    clino  
       Oct 24, 2012
    枚举出来的 ip 也都不能用呀...
    phuslu
        14
    phuslu  
    OP
       Oct 24, 2012
    @clino 呃, 不能用是指?
    clino
        15
    clino  
       Oct 24, 2012
    @phuslu 用在 /etc/hosts 里不行啊,直接用 http://ip 也连不上呀
    phuslu
        16
    phuslu  
    OP
       Oct 24, 2012
    @clino 嗯, 可能是你的网络环境(ISP?)的问题, wget http://ip 可以用吗?
    clino
        17
    clino  
       Oct 24, 2012
    @phuslu 汗,我在家想试试看,结果就完全没有 ip 出来,可能你设的这个网段已经屏蔽光了
    phuslu
        18
    phuslu  
    OP
       Oct 24, 2012
    @clino 换成 46.x 47.x 48.x 等网段试下呢
    cmsee
        19
    cmsee  
       Nov 6, 2012
    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  
       Feb 17, 2013
    大哥,这个不能用了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 ================================
    >>> ,如何处理?多谢!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   826 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 19:19 · PVG 03:19 · LAX 12:19 · JFK 15:19
    ♥ Do have faith in what you're doing.