m

#coding=utf-8

from Tkinter import * 

import os

import sys

reload(sys)

sys.setdefaultencoding('utf-8')

import Tkinter, Tkconstants, tkFileDialog 

def on_click():

 filename=tkFileDialog.askopenfilename(initialdir='c:\\')   

file=open(filename)  

line=file.readlines()  

label['text']=line

 

 

 

root= Tk(className='杨') 

label = Label(root) 

label['text'] = '请放入文件'

label.pack()

text=StringVar()

text.set('9180')

entry=Entry(root)

entry['textvariable']=text

entry.pack()

button_opt = {'fill': Tkconstants.BOTH, 'padx': 5, 'pady': 5} 

button_click = Button(root,text='获取',command=on_click).pack(button_opt)

button_quit = Button(root,text='quit',command=quit).pack(button_opt)

print entry,text

 

root.mainloop()

root.destroy()

 =====================================

#coding:utf-8
# -*- coding: utf-8 -*-
import os
import re
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

import urllib2
import re


#外网IP
#print re.search('\d+\.\d+\.\d+\.\d+',urllib2.urlopen("http://www.ip138.com/ip2city.asp").read()).group(0)


def GetFileList(dir, fileList):
  newDir = dir
  if os.path.isfile(dir):
    fileList.append(dir.decode('gbk'))
  elif os.path.isdir(dir):
    for s in os.listdir(dir):
    #如果需要忽略某些文件夹,使用以下代码
    #if s == "xxx":
    #continue
    newDir=os.path.join(dir,s)
    GetFileList(newDir, fileList)
  return fileList

def filename():
  list = GetFileList('.\\', [])
  #print aa
  for a in list:
    b=a.split('\\')[1]
    #print b
    if None != re.search('[i][p](.*?)[t][x][t]',a):break
  #print b
  file=open(b)
  line=file.readline()
  PID='4828'


  while line:
    x=line.split(',') #0是序号,1是进程ID,2是进程名称, 3是远端IP, 4是远端端口,5是本机IP,6是本机端口,7是发送字节,8是接收字节,9是最后访问时间,10是远端IP位置
    #print x
    leida_PID=x[1].strip()

    #print leida_PID,PID
    #print '进程ID',x[1],'进程名',x[2],'远端IP',x[3],'归属地',x[10]
    if leida_PID==PID:
      x1=x[1]
      x2=x[2]
      x3=x[3]
      x10=x[10]
      l='进程ID%s进程名%s远端IP%s归属地%s'%(x1,x2,x3,x10)
      wfile=open('3','a')
      wfile.writelines(l)
      print l

 

  # print '进程ID',x[1],'进程名',x[2],'远端IP',x[3],'归属地',x[10]

 

  line=file.readline()

 

if __name__ == '__main__':
  filename()

 

posted @ 2017-03-16 19:07  monster_ygs  阅读(362)  评论(0编辑  收藏  举报