Measure Network Data with Python

前端 未结 1 2007
谎友^
谎友^ 2020-12-31 10:47

I\'m currently writing a program to shut down a computer when over a period of time (say, half an hour) network traffic is below a certain threshold.

Here\'s the pse

相关标签:
1条回答
  • 2020-12-31 10:54

    To check the network traffic on your system, i recommend you look into psutil:

    >>> psutil.net_io_counters(pernic=True)
    {'lo': iostat(bytes_sent=799953745, bytes_recv=799953745, packets_sent=453698, packets_recv=453698), 
     'eth0': iostat(bytes_sent=734324837, bytes_recv=4163935363, packets_sent=3605828, packets_recv=4096685)}
    >>>
    

    And to shutdown your OS, if you are on windows check this: OS Reboot, Shutdown, Hibernate, Sleep, Wakeup (Windows Python)

    and if you are using linux/unix, use the subprocess module to send the shutdown/reboot command.

    0 讨论(0)
提交回复
热议问题