推荐学习书目
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
zhujunhan7
V2EX  ›  Python

能不能写一个不停监测一个 ip,上线和下线用 srver 酱关联微信提醒的小程序。

  •  
  •   zhujunhan7 · Nov 18, 2018 via iPad · 3558 views
    This topic created in 2779 days ago, the information mentioned may be changed or developed.
    7 replies    2018-11-19 12:58:05 +08:00
    Event
        1
    Event  
       Nov 18, 2018
    你好 可以 再见
    annoy1309
        2
    annoy1309  
       Nov 18, 2018
    能,不难
    AlisaDestiny
        3
    AlisaDestiny  
       Nov 18, 2018
    easy.具体需求说下。
    wdc63
        4
    wdc63  
       Nov 18, 2018
    '''python
    #pip install requests
    import subprocess, platform
    import requests
    import time
    def ping(host):
    """
    Returns True if host responds to a ping request
    """
    import subprocess, platform

    # Ping parameters as function of OS
    ping_str = "-n 1" if platform.system().lower()=="windows" else "-c 1"
    args = "ping " + " " + ping_str + " " + host
    need_sh = False if platform.system().lower()=="windows" else True

    # Ping
    return subprocess.call(args, shell=need_sh) == 0

    on_state = 1
    off_state = 1


    def watch(host):
    global on_state, off_state
    while True:
    get_ping = ping(host)
    if get_ping:
    ##如果检测到在线,且离线状态为真(off_state>0),发送上线信号,并将离线状态重置为假(=0 )
    if off_state > 0:
    off_state = 0
    requests.get("https://sc.ftqq.com/[SCKEY(登入后可见)].send?text=服务器上线!")
    else:
    on_state += 1
    else:
    ##如果检测到连续离线五次,且在线状态为真(off_state>0),发送离线信号,并将在线状态重置为假(=0 )
    if on_state > 0 and off_state >= 5:
    on_state = 0
    requests.get("https://sc.ftqq.com/[SCKEY(登入后可见)].send?text=服务器离线!")
    else:
    off_state += 1
    time.sleep(1)

    watch('www.baidu.com')
    '''
    wdc63
        5
    wdc63  
       Nov 18, 2018
    https://gist.github.com/wdc63/869c104ac43841f20b25a40b4dd3b7d9

    不会插代码,晕死,拿去试试,随便写了,没有试运行过
    Tink
        6
    Tink  
    PRO
       Nov 19, 2018 via iPhone
    很简单
    winglight2016
        7
    winglight2016  
       Nov 19, 2018
    8 年以前写过一个 Android app 就是做这个事儿的,好久没维护了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3604 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 192ms · UTC 00:47 · PVG 08:47 · LAX 17:47 · JFK 20:47
    ♥ Do have faith in what you're doing.