while 循环对齐列
你好 我编写了一个 perl 脚本,其中将填充 ip 和端口扫描的文本文件中的列存储到变量中。这些变量包含许多 ip 地址、端口、协议、状态和服务,现在我需要一个 while 循环,它获取 ip 变量中存储的所有 ip,并将它们与其相应的端口、协议和状态等进行匹配。并排看起来如下: 192.168.3 45 tcp open smtp
这是我的代码
$ip_address = `cat /cygdrive/c/Windows/System32/test11.txt |
grep 'Nmap scan report for'`;
$state = `cat /cygdrive/c/Windows/System32/test11.txt | grep -v 'PORT'|
grep -v 'filtered'| grep -v 'latency'| grep -v 'Nmap' | grep -v 'Discovered' |
grep -v 'Raw' | grep -v 'SYN' | grep -v 'DNS'| grep -v 'Ping' |
grep -v 'Scanning' `;
$port = `cat /cygdrive/c/Windows/System32/test11.txt | grep -v 'Discovered'|
grep -v 'Nmap' | grep -v 'PORT' | grep -v 'ports'| grep -v 'Read' |
grep -v 'Raw'| grep -v 'Completed'| grep -v 'DNS' | grep -v 'hosts' |
grep -v 'Ping' | grep -v 'SYN' | grep -v 'latency' `;
$protocol = `cat /cygdrive/c/Windows/System32/test11.txt | grep -v 'Discovered'|
grep -v 'Nmap' | grep -v 'PORT' | grep -v 'ports'| grep -v 'Read' |
grep -v 'Raw' | grep -v 'Completed'| grep -v 'DNS' | grep -v 'hosts' |
grep -v 'Ping' | grep -v 'SYN' | grep -v 'latency' `;
{
$service = `cat /cygdrive/c/Windows/System32/test11.txt | grep -v 'Nmap' |
grep-v 'Host' | grep -v 'filtered' | grep -v 'PORT' | grep -v 'Raw'|
grep -v 'Scanning'| grep -v 'Completed'| grep -v 'Ping' |grep -v 'DNS' |
grep -v 'Discovered'| grep -v 'SYN'`;
while($ip_address, $port, $protocol, $state, #service)
{
chomp ($ip_address, $port, $protocol, $state, #service);
print "$ip_address, $port, $protocol, $state, #service";
exit 0;
}
hi
I wrote a perl script where I stored columns from a text file filled with ip and port scans into variables. The variables contain many ip addreses, ports, protocols, states, and services now I need a while loop that takes all the ip's stored in the ip variable and matches them with its corresponding ports protocols and state etc.side by side look so:
192.168.3 45 tcp open smtp
heres my code
$ip_address = `cat /cygdrive/c/Windows/System32/test11.txt |
grep 'Nmap scan report for'`;
$state = `cat /cygdrive/c/Windows/System32/test11.txt | grep -v 'PORT'|
grep -v 'filtered'| grep -v 'latency'| grep -v 'Nmap' | grep -v 'Discovered' |
grep -v 'Raw' | grep -v 'SYN' | grep -v 'DNS'| grep -v 'Ping' |
grep -v 'Scanning' `;
$port = `cat /cygdrive/c/Windows/System32/test11.txt | grep -v 'Discovered'|
grep -v 'Nmap' | grep -v 'PORT' | grep -v 'ports'| grep -v 'Read' |
grep -v 'Raw'| grep -v 'Completed'| grep -v 'DNS' | grep -v 'hosts' |
grep -v 'Ping' | grep -v 'SYN' | grep -v 'latency' `;
$protocol = `cat /cygdrive/c/Windows/System32/test11.txt | grep -v 'Discovered'|
grep -v 'Nmap' | grep -v 'PORT' | grep -v 'ports'| grep -v 'Read' |
grep -v 'Raw' | grep -v 'Completed'| grep -v 'DNS' | grep -v 'hosts' |
grep -v 'Ping' | grep -v 'SYN' | grep -v 'latency' `;
{
$service = `cat /cygdrive/c/Windows/System32/test11.txt | grep -v 'Nmap' |
grep-v 'Host' | grep -v 'filtered' | grep -v 'PORT' | grep -v 'Raw'|
grep -v 'Scanning'| grep -v 'Completed'| grep -v 'Ping' |grep -v 'DNS' |
grep -v 'Discovered'| grep -v 'SYN'`;
while($ip_address, $port, $protocol, $state, #service)
{
chomp ($ip_address, $port, $protocol, $state, #service);
print "$ip_address, $port, $protocol, $state, #service";
exit 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常我会说使用您理解的工具,并且可以执行诸如从 Perl 调用
awk
之类的操作。但对于这段代码我会破例。您应该使用内置的Perl
命令来完成此任务。即数组和 Perl 的 grep 运算符。这就是我将如何开始重写这个。Usually I say to use the tools that you understand and that it's OK to do things like call
awk
from Perl. But for this code I'll make an exception. You should be using the builtinPerl
commands for this task. Namely, arrays and Perl'sgrep
operator. Here's how I would start to rewrite this.我通常尝试一次性完成这些事情,比如......
I usually try to do these sorts of things in one pass, like...