C/C++ 中 system() 的惊人用法?
我们将在文中看到一些利用 C 或 C++ 中的 system() 函数获得的惊人成果。system 函数存在于 Windows、Linux 和 MAC 操作系统中。此函数用于执行可以在命令行中编写的系统命令。
下面我们将看到 system 函数在 C 或 C++ 中的两个用法。第一个用法是使用 C++ 程序获取 IP 配置详细信息。
示例
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
system("C:\Windows\System32\ipconfig");
}输出
Windows IP Configuration
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . : domain.name
Link-local IPv6 Address . . . . . : fe80::302b:9dff:1cfb:ff01%10
IPv4 Address. . . . . . . . . . . : 192.168.2.6
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : fe80::217:7cff:fe3d:31c8%10
192.168.2.1
Ethernet adapter VirtualBox Host-Only Network:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::5c79:a124:f5b9:e0b7%13
Autoconfiguration IPv4 Address. . : 169.254.224.183
Subnet Mask . . . . . . . . . . . : 255.255.0.0
Default Gateway . . . . . . . . . :
Ethernet adapter VirtualBox Host-Only Network #2:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::7c54:289:9257:dd7a%16
IPv4 Address. . . . . . . . . . . : 192.168.243.2
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
Tunnel adapter Teredo Tunneling Pseudo-Interface:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Tunnel adapter isatap.{E12FA520-1578-4264-A565-A1270D18177A}:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Tunnel adapter isatap.{A01195C5-0A34-4E50-89CB-4C391165B7C3}:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Tunnel adapter isatap.domain.name:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . : domain.name第二个用法更有趣。我们可以通过它关闭我们的计算机。我们只需在 system 函数中写入关闭程序路径即可。
示例
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
system("C:\WINDOWS\System32\shutdown /s");
}输出
One box will appear. It will tail the system is shutting down, then it will be shut down.
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP