python获取ESTABLISHED

python获取ESTABLISHED
  • 2024-09-05
#!/usr/bin/env python3 #-*- coding:utf-8 -*- #create at 2018-12-07 'this is a system monitor scripts' __author__="yjt" import os import time import sys import datetime import socket import psutil import re import json #以下是变量值,自己定义 CPUT = 2 #计算CP
python获取系统信息psutil:psutil获取系统cpu使用率的方法是cpu_percent(),其有两个参数,分别是interval和percpu,interval指定的是计算cpu使用率的时间间隔,percpu则指定是选择总的使用率还是每个cpu的使用率. import psutil #cpu使用率 cpu=(str)(psutil.cpu_percent(1))+'%' #剩余内存.free 总共.total memory=str(psutil.virtual_memory().f
一直以来被Linux的hostname和fqdn(Fully Qualified Domain Name)困惑了好久,今天专门抽时间把它们的使用细节弄清了. 一.设置hostname/fqdn 在Linux系统内设置hostname很简单,如: $ hostname florian 如果要设置fqdn的话,需要对/etc/hosts进行配置. $ cat /etc/hosts 127.0.0.1 localhost 192.168.1.1 florian.test.com florian /et
python获取字母在字母表对应位置的几种方法及性能对比较 某些情况下要求我们查出字母在字母表中的顺序,A = 1,B = 2 , C = 3, 以此类推,比如这道题目 https://projecteuler.net/problem=42 其中一步解题步骤就是需要把字母换算成字母表中对应的顺序. 获取字母在字母表对应位置的方法,最容易想到的实现的是: 使用str.index 或者str.find方法: In [137]: "ABC".index('B') Out[137]: 1 In
python获取文件大小 # !/usr/bin/python3.4 # -*- coding: utf-8 -*- import os # 字节bytes转化kb\m\g def formatSize(bytes): try: bytes = float(bytes) kb = bytes / 1024 except: print("传入的字节格式不对") return "Error" if kb >= 1024: M = kb / 1024 if M &g
python 获取一个列表有多少连续列表 例如 有列表 [1,2,3] 那么连续列表就是 [1,2],[2,3],[1,2,3] 程序实现如下: 运行结果:
python获取当前时间的前一天,前一周,前一个月. 实用python的datetime.timedelta方法,避免了有的月份是30和31等不同的情况. 获取前一个月的时间,方法实现:首先datetime.datetime.now获取当前时间,然后通过datetime.timedelta获取上一个月最后一天的datetime对象dayto,最后用dayto的数据初始化这个月的第一个天和最后一天的datetime对象. import datetime d = datetime.datetime.
Python获取指定路径下的子目录和文件有两种方法: os.listdir(dir)和os.walk(dir),前者列出dir目录下的所有直接子目录和文件的名称(均不包含完整路径),如 >>> os.listdir(r'E:')['$RECYCLE.BIN', 'Download', 'test.txt', 'data', 'MyDownloads', 'System Volume Information', 'VSPath', 'Youku Files']>>> 后者
/*********************************************************************** * Python 获取 网卡 MAC 地址 * 说明: * 记录一下Python如何获取网卡MAC地址,主要用于数据唯一性保存. * * 2016-10-15 深圳 南山平山村 曾剑锋 **********************************************************************/ 一.参考文档: pyth
python 获取 mac 地址 的例子,有需要的朋友可以参考下. #!/bin/python import os import re def GetMac():     if os.name == 'nt':         try:             ret = ''             CmdLine = 'ipconfig /all'             r = os.popen(CmdLine).read()             if r:              
其实最好的办法是写个单独的脚本去查找IP,但是如果实在不愿意单写一个脚本文件,也可以直接将代码嵌入.bashrc中 在~/.bashrc下加入下面这行代码即可使用python获取本机的wlan的IP地址并导出到MY_IP变量中 export MY_IP=$(python -c "import re;e = re.search(r'wlan\d+ Link encap\:Ethernet HWaddr \w{2}\:\w{2}\:\w{2}\:\w{2}\:\w{2}\:\w{2} inet ad
Python获取mac 获取计算机名字和ip(内网ip) 指定网卡ip
在python中获取ip地址和在php中有很大不同,在php中往往比较简单.那再python中怎么做呢? 我们先来看一下python 获得本机MAC地址: 1 2 3 4 import uuid def get_mac_address():      mac=uuid.UUID(int = uuid.getnode()).hex[-12:]      return ":".join([mac[e:e+2] for e in range(0,11,2)]) 下面再来看一下python获取
今天我们来看一下如何用python获取网络时间和本地时间,直接上代码吧,代码中都有注释. python获取网络时间 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 获取网络时间  def getBeijinTime():      """   获取北京时间      """      try:          conn = httplib
Python 获取时间通过 time 模块 如下代码,是通过获取当前的时间,按照格式输出 Python默认获取当前的时间返回的都是时间的元组,下面是元组的,字符串时间的一个转换输出 # -*- coding:utf-8 -*- import time #Python 获取时间戳 #Python 默认获取的时间是一个具有时间的元组,asctime() 是接受时间元祖,返回一个时间字符串 TimeTuple=time.localtime(time.time()) #获取当前的时间返回一个时间元组 p
一直以来被Linux的hostname和fqdn(Fully Qualified Domain Name)困惑了好久,今天专门抽时间把它们的使用细节弄清了. 一.设置hostname/fqdn 在Linux系统内设置hostname很简单,如: $ hostname florian 如果要设置fqdn的话,需要对/etc/hosts进行配置. $ cat /etc/hosts 127.0.0.1 localhost 192.168.1.1 florian.test.com florian /et
一.shell获取脚本当前路径 cur_dir=$(cd "$(dirname "$0")"; pwd)  #获取当前脚本的绝对路径,参数$0是当前脚本对象 等同于cd `dirname $0`; pwd 但是,cd "dirname $0";pwd是错的,因为dirname不能用双引号 代码实例: echo $(cd `dirname$0`;pwd) TEST=`cd $(dirname $0);pwd` echo $TEST 输出: /roo
python语言中的datetime模块可以利用其中的方法获取不同的日期,比如获取当前日期.明天.昨天.上个月.下个月和明年.下面利用几个实例说明这些日期的获取方法,操作如下:     第一步,利用datetime模块获取当前日期datetime.date.today();如下图所示:     第二步,获取当前日期前一天日期,利用当前日期减去一天,如下图所示:     第三步,获取当前日期后一天日期,利用当前日期加上一天,如下图所示:     第四步,获取当前日期下一个月日期,利用当前日期加上3
python获取set-cookies #!/usr/bin/python3.4 # -*- coding: utf-8 -*- import requests url = "https://www.baidu.com/" session = requests.session() session.get(url) html_set_cookie = requests.utils.dict_from_cookiejar(session.cookies) print(html_set_co
通过python获取当前mac地址的方法如下:(1)通用方法,借助uuid模块def get_mac_address(): import uuid      node = uuid.getnode()      mac = uuid.UUID(int = node).hex[-12:] return mac (2)按照操作系统平台来def get_mac_address():    '''    @summary: return the MAC address of the computer  

热门专题