小demo:
# -*- coding: utf-8 -*-
"""第乙個程式"""
import subprocess
print ("hello world!" )
print ("hello again")
print ("i like typing this.")
print ("this is fun.")
print ('yay! printing.')
print ("i'd much rather you 'not'.")
print ('i "said" do not touch this.')
import os
result = os.popen("ipconfig")
# print (result.read())
# raw_data = subprocess.popen("netstat -ano", stdout=subprocess.pipe, shell=true)
# raw_data = raw_data.stdout.read().decode("gbk").split('\r\n')[4:] # 去掉4行頭
# print("chuliqian", raw_data)
def get_port_info():
raw_data = subprocess.popen("netstat -ano", stdout=subprocess.pipe, shell=true)
raw_data = raw_data.stdout.read().decode("gbk").split('\r\n')[4:] # 去掉4行頭
print("chuliqian", raw_data)
for line in raw_data[:]: # 要加個raw_data[:]
lineline = line.split(" ")
print(lineline)
black_list = ["udp", " [::]:0", "[::]:0", " time_wait", "time_wait", "close_wait", " close_wait",
" established", "established", " syn_sent", "syn_sent"]
for k, v in enumerate(black_list):
if v in lineline:
raw_data.remove(line)
while '' in raw_data:
raw_data.remove('')
print("chulihou:", raw_data)
port_list =
for line in raw_data:
port_dict = {}
port_info = line.split()
print(port_info)
port_num = port_info[1].split(':')[-1] # 本機開放的埠
listen_addr = port_info[1].split(':')[0] # 本機ip位址
pid = int(port_info[4]) # windows的pid號
cmd = 'tasklist | findstr "%s"' % (pid) # 根據pid號執行命令
process_data = subprocess.popen(cmd, stdout=subprocess.pipe, shell=true) # 執行命令獲取pid的程序資訊
process_name = process_data.stdout.read().decode("gbk").split(" ")[0].split(".")[0] # 取出pid所對應的程序名字mysqld
# port = getpidinfo(pid) # 實現根據程序名字對應用名字和應用版本號提取
# exe_path = port.get_exe_path()
# service_name = port.get_exe_name(exe_path)
# service_version = port.get_exe_version(exe_path)
port_dict['port_num'] = port_num
port_dict['listen_addr'] = listen_addr
port_dict['pid'] = str(pid)
port_dict['process_name'] = process_name # 程序的名字
# port_dict['service_name'] = service_name # 應用的名字
# port_dict['service_version'] = service_version # 應用的版本
if port_dict not in port_list:
port_list = [i for i in port_list if i] # 去掉空字典
print(port_list)
if __name__ == '__main__':
get_port_info()
pip install pyinstaller
anaconda3\scripts>pyinstaller.exe -f c:\users\liangyi\desktop\pythonexedemo\hello.py
在scripts 下生成乙個2個資料夾
build 不用去管,可以直接刪除。開啟dist 檔案
結束!
python 編譯EXE檔案
標註工具labelimg和labelme 矩形標註工具 labelimg 多邊形標準工具 labelme 前者官網發布了可執行檔案,後者只有python原始碼,如果需要編譯windows exe,可以這樣 pip install labelme然後執行labelme確保程式可以正常執行 cd d g...
把python檔案編譯成exe檔案
把python檔案編譯成exe檔案 2008年06月24日 星期二 下午 08 37 把python 編譯成exe檔案是一件很酷的事情,有很多軟體都能實現這個功能。1.py2exe鏈結 安裝比較簡單,一路下一步就行了。建立乙個例子檔案foobar.py print foobar 建立乙個安裝檔案se...
python 生成exe檔案
安裝pyinstaller anacona使用 anaconda prompt 進入命令列 pip install pyinstaller 打包成單獨檔案 pyinstaller f py過程中可能出現的問題 import sys sys.setrecursionlimit 1000000 例如這裡...