서문
교통정보는 /proc/net/dev
에서 직접 볼 수 있습니다. 저자가 구현한 프로그램은
python net.py interface명령을 사용합니다.
interface
이 네트워크 카드 이름인 경우, 어떤 네트워크 카드가 사용되는지, 컴퓨터에 어떤 네트워크 카드가 있는지는
sudo ifconfig
확인해보세요.
Python으로 구현한 프로그램은 다음과 같습니다.
# coding:utf-8 import sys, time, os ''' Inter-| Receive | Transmit face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed lo: 28169 364 0 0 0 0 0 0 28169 364 0 0 0 0 0 0 wlan1: 7432984 6018 0 0 0 0 0 0 681381 6115 0 0 0 0 0 0 vmnet1: 0 0 0 0 0 0 0 0 0 56 0 0 0 0 0 0 vmnet8: 0 0 0 0 0 0 0 0 0 55 0 0 0 0 0 0 eth0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ''' _unit_=['B','KB','MB','GB','TB'] def get_net_data(interface): for line in open('/proc/net/dev', 'r'): if line.split(':')[0].find(interface)>=0: return map(int, line.split(':')[1].split()) def convert_bytes_to_string(b): cnt = 0 while b >= 1024.0: b = float(b) / 1024.0 cnt += 1 return '%.2f%s'%(b,_unit_[cnt]) if __name__ == '__main__': interface = sys.argv[1] while True: net_data = get_net_data(interface) receive_data_bytes = net_data[0] transmit_data_bytes = net_data[8] os.system('clear') print 'Interface:%s -> Receive Data: %s Transmit Data: %s'%(interface, convert_bytes_to_string(receive_data_bytes), convert_bytes_to_string(transmit_data_bytes)) time.sleep(1)
프로그램 항목은 if name=='main'
에서 시작하려면 먼저 매개변수를 통해 interface
를 가져온 다음 get_net_data()
함수를 호출하여 교통 정보를 가져온 다음 일부 데이터를 처리합니다.
요약
위 내용은 모두의 공부나 업무에 도움이 되었으면 좋겠습니다. 따라서 궁금한 점이 있으면 메시지를 남겨서 소통할 수 있습니다.
Python에서 시스템 네트워크 트래픽을 보는 방법에 대한 자세한 내용은 PHP 중국어 웹사이트를 참고하세요!

Pythonusesahybridmodelofilationandlostretation : 1) ThePyThoninterPretreCeterCompileSsourcodeIntOplatform-IndependentBecode.

Pythonisbothingretedandcompiled.1) 1) it 'scompiledtobytecodeforportabilityacrossplatforms.2) thebytecodeisthentenningreted, withfordiNamictyTeNgreted, WhithItmayBowerShiledlanguges.

forloopsareusedwhendumberofitessiskNowninadvance, whilewhiloopsareusedwhentheationsdepernationsorarrays.2) whiloopsureatableforscenarioScontiLaspecOndCond

pythonisnotpurelynlogreted; itusesahybrideprophorfbyodecodecompilationandruntime -INGRETATION.1) pythoncompilessourcecodeintobytecode, thepythonVirtualMachine (pvm)

ToconcatenatelistsinpythonwithesameElements, 사용 : 1) OperatorTokeEpduplicates, 2) asettoremovedUplicates, or3) listComperensionForControlOverDuplicates, 각 methodHasDifferentPerferformanCeanDorderImpestications.

PythonisancerpretedLanguage, 비판적 요소를 제시하는 PytherfaceLockelimitationsIncriticalApplications.1) 해석 된 언어와 같은 thePeedBackandbackandrapidProtoTyping.2) CompilledlanguagesLikec/C transformt 해석

useforloopswhhenmerfiterationsiskNownInAdvance 및 WhileLoopSweHeniTesslationsDepoyConditionismet whilEroopsSuitsCenarioswhereTheLoopScenarioswhereTheLoopScenarioswhereTheLoopScenarioswhereTherInatismet, 유용한 광고 인 푸트 gorit


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전

WebStorm Mac 버전
유용한 JavaScript 개발 도구