加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl 扫描域名,ip地址,mac地址, 服务器开放端口信息

发布时间:2020-12-16 00:19:22 所属栏目:大数据 来源:网络整理
导读:script 说明: ? 该script可以扫描指定服务器的如下信息,并发邮件通知。 用来自动创建服务器管理文档也很有效。包括:域名,ip地址,mac地址, 服务器开放的端口。 ? #!/usr/bin/perl?-w? use?strict;? use?Mail::Sender;? my?@servers=qw(10.13.55.1?10.13
script 说明:

?

该script可以扫描指定服务器的如下信息,并发邮件通知。 用来自动创建服务器管理文档也很有效。
包括:域名,ip地址,mac地址, 服务器开放的端口。

?

 
 
  1. #!/usr/bin/perl?-w?
  2. use?strict;?
  3. use?Mail::Sender;?
  4. my?@servers=qw(10.13.55.1?10.13.55.2?10.13.55.3);?#在这里添加需要扫描的主机
  5. foreach?my?$host?(@servers)?{?
  6. ????????my?$nmap=`nmap?-O?$host`;?
  7. ????????open?(AF,?'>nmap_scan')?or?die?"open?error:?$!n";?
  8. ????????print?AF?$nmap;?
  9. ????????close(AF);?
  10. ????????my?@results;?
  11. ????????my?@port;?
  12. ????????open?(INPO,?'nmap_scan');?
  13. ????????foreach?my?$list?(<INPO>)?{?
  14. ????????????????chomp($list);?
  15. ????????????????if?(Match_word($list))?{?
  16. ????????????????????????push(@results,?Match_word($list));?
  17. ????????????????};?
  18. ????????????????if?(Match_port($list))?{?
  19. ????????????????????????push(@port,?Match_port($list));?
  20. ????????????????};?
  21. ????????};?
  22. ????????close(INPO);?
  23. ????????print?"@resultsn";?
  24. ????????@port=join("/",?@port);?
  25. ????????print?"opened?port:?@portnn";?
  26. ????????@results=undef;?
  27. ????????@port=undef;?
  28. };?
  29. ?
  30. ?
  31. sub?Match_word?{?
  32. ????????my?@lists;?
  33. ????????my?@result;?
  34. ????????my?@ser_port;?
  35. ????????my?$list=shift;?
  36. ????????if?($list=~/^Nmap?scan?report?for/)?{?
  37. ????????????????@lists=split(/s/,?$list);?
  38. ????????????????$lists[5]=~s/[(|)|s+]//g;?
  39. ????????????????push(@result,?$lists[4],?$lists[5]);?
  40. ????????????????return?@result;?
  41. ????????};?
  42. ?
  43. ????????if?($list=~/^MAC/)?{?
  44. ????????????????@lists=split(/s/,?$list);?
  45. ????????????????$lists[2]=~s/s+//g;?
  46. ????????????????return?$lists[2];?
  47. ????????};?
  48. ?
  49. ?
  50. ????????if?($list=~/^Running/)?{?
  51. ????????????????@lists=split(/:s/,?$list);?
  52. ????????????????return?$lists[1];?
  53. ?
  54. ????????};?
  55. }?
  56. ?
  57. sub?Match_port?{?
  58. ????????my?$list=shift;?
  59. ????????if?($list=~/open/)?{?
  60. ????????????????my?@lists=split(/s+/,?$list);?
  61. ????????????????my?@aaa=split(///,?$lists[0]);?
  62. ????????????????return?"$aaa[0]";?
  63. ????????};?
  64. }?
  65. sub?Send_mail?{?
  66. ????????my?$subject=shift;?
  67. ????????my?$msg=shift;?
  68. my?$sender=new?Mail::Sender->MailMsg({?
  69. ?????????smtp?=>?'mail.aaa.com',?
  70. ?????????from?=>?'neo@aaa.com',?
  71. ?????????to?=>'neo.@gmail.com',?
  72. ?????????subject?=>?$subject,?
  73. ?????????msg?=>?$msg,?
  74. ?????????auth?=>?'LOGIN',?
  75. ?????????authid?=>?'neo',?
  76. ?????????authpwd?=>?'1234',}?
  77. )?or?die?"$Mail::Sender::Errorn";?
  78. print?"Mail?sent?ok";?
  79. }?

?


script 执行结果:
包括:域名,ip地址,mac地址, 服务器开放的端口。

root@ubuntu:~/script# perl services_info_scan

link.aaa.com.cn 10.13.55.1 00:0D:48:09:02:0B

opened port: 22/80/443/2005


fs.aaa.com.cn 10.13.55.2 00:1F:C6:14:1F:9E Microsoft Windows 2003

opened port: 53/80/88/135/389/445/464/593/636/1025/1027/1036/1060/1723/2000/3268/3269/3389


mail.aaa.com.cn 10.13.55.3 00:0C:29:D9:58:6E Linux 2.4.X

opened port: 22/25/53/110/111/143/587/3000/32768

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读