1. 程式人生 > >虛擬機有QQ消息時宿主機自動彈窗提示

虛擬機有QQ消息時宿主機自動彈窗提示

tkinter span 。。 recv ast none messages sage accep

因為是檢測窗口實現的,所以要求看完消息就把QQ消息窗口關掉。。。

虛擬機端

 1 #! /usr/bin/env python
 2 # -*- coding: utf-8 -*-
 3 
 4 from win32gui import *
 5 import time
 6 import socket
 7 HOST = 192.168.0.126
 8 PORT = 8001
 9 titles = set()
10 def foo(hwnd,mouse):
11     #去掉下面這句就所有都輸出了
12     if IsWindow(hwnd) and
IsWindowEnabled(hwnd) and IsWindowVisible(hwnd): 13 if GetClassName(hwnd)==TXGuiFoundation: 14 titles.add(GetWindowText(hwnd)) 15 16 def send_message(): 17 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 18 s.connect((HOST, PORT)) 19 s.send(You\‘ve got some new QQ messages.
) 20 data = s.recv(1024) 21 print data 22 23 last=None 24 while True: 25 titles=set() 26 EnumWindows(foo, 0) 27 lt = [t for t in titles if t] 28 lt.sort() 29 if last!=lt: 30 print got 31 send_message() 32 last=lt 33 time.sleep(1)

宿主機端

 1 #encoding=utf-8
 2 import Tkinter as tk
 3 import socket
 4 
 5 def create_message_dialog():
 6     top = tk.Tk()
 7     top.title("QQ Message")
 8     top.geometry(400x400)
 9     labelHello = tk.Label(top, text = "You‘ve got new QQ messages.")
10     labelHello.pack()
11     top.mainloop()
12 
13 HOST = 192.168.0.126
14 PORT = 8001
15 
16 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
17 s.bind((HOST, PORT))
18 s.listen(5)
19 
20 print Server start at: %s:%s %(HOST, PORT)
21 print wait for connection...
22 
23 while True:
24     conn, addr = s.accept()
25     print Connected by , addr
26     data = conn.recv(1024)
27     print data
28     if data==You\‘ve got some new QQ messages.:
29         create_message_dialog()
30     conn.send("server received you message.")
31     conn.close()

END

2017.8.17 19:58

虛擬機有QQ消息時宿主機自動彈窗提示