虚拟机有QQ消息时宿主机自动弹窗提示
Posted maxuewei2
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了虚拟机有QQ消息时宿主机自动弹窗提示相关的知识,希望对你有一定的参考价值。
因为是检测窗口实现的,所以要求看完消息就把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消息时宿主机自动弹窗提示的主要内容,如果未能解决你的问题,请参考以下文章