BW-seq-ftp.pl
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:4k
源码类别:

通讯编程

开发平台:

Visual C++

  1. #!/usr/bin/perl -w
  2. #
  3. # Copyright (C) 2001 by USC/ISI
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms are permitted
  7. # provided that the above copyright notice and this paragraph are
  8. # duplicated in all such forms and that any documentation, advertising
  9. # materials, and other materials related to such distribution and use
  10. # acknowledge that the software was developed by the University of
  11. # Southern California, Information Sciences Institute.  The name of the
  12. # University may not be used to endorse or promote products derived from
  13. # this software without specific prior written permission.
  14. #
  15. # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
  16. # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  17. # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18. #
  19. # An tcl script that extracts DATA/ACK packets from/to ISI domain, 
  20. # used by SAMAN ModelGen
  21. #
  22. # This work is supported by DARPA through SAMAN Project
  23. # (http://www.isi.edu/saman/), administered by the Space and Naval
  24. # Warfare System Center San Diego under Contract No. N66001-00-C-8066
  25. #
  26. sub usage {
  27.         print STDERR <<END;
  28.         usage: $0 [-r Filename] [-s DomainPrefix]
  29.         Options:
  30.             -r string  file that contains a list of FTP clients, which
  31.                        is output of getFTPclient.pl
  32.     -s string  specify IP prefix to distinguish Inbound from 
  33.                outbound traffic (eg. 192.1)
  34. END
  35. exit 1;
  36. }
  37. BEGIN {
  38.      $dblibdir = "./";
  39. push(@INC, $dblibdir);
  40. }
  41. use DbGetopt;
  42. require "dblib.pl";
  43. my(@orig_argv) = @ARGV;
  44. &usage if ($#ARGV < 0);
  45. my($prog) = &progname;
  46. my($dbopts) = new DbGetopt("r:s:?", @ARGV);
  47. my($ch);
  48. while ($dbopts->getopt) {
  49.         $ch = $dbopts->opt;
  50.         if ($ch eq 'r') {
  51.                 $infile = $dbopts->optarg;
  52.         } elsif ($ch eq 's') {
  53. $prefix = $dbopts->optarg;
  54.         } else {
  55.                 &usage;
  56.         };
  57. };
  58. ($ip1,$ip2,$ip3,$ip4,$m1,$m2,$m3,$m4) = split(/[./ ]/,$prefix);
  59. $ip3="";
  60. $ip4="";
  61. $m1="";
  62. $m2="";
  63. $m3="";
  64. $m4="";
  65. $isiPrefix=join(".",$ip1,$ip2);
  66. open(OUT,"> outbound.seq") || die("cannot open outbound.seqn");
  67. open(IN,"> inbound.seq") || die("cannot open inbound.seqn");
  68. open(FIN,"< $infile") || die("cannot open $infilen");
  69. $num_ftp=0;
  70. while (<FIN>) {
  71.    ($host,$newline) = split(/[:() n]/,$_);
  72.    $newline="";
  73.    $ftpC[$num_ftp]=$host;
  74.    $num_ftp++;
  75. }
  76. close(FIN);
  77. while (<>) {
  78.         ($time1,$time2,$ip11,$ip12,$ip13,$ip14,$srcPort,$dummy1,$ip21,$ip22,$ip23,$ip24,$dstPort,$dummy2,$flag,$seqb,$seqe,$size,$size1) = split(/[.:() ]/,$_);
  79. #        ($time1,$time2,$dummy0,$ip11,$ip12,$ip13,$ip14,$srcPort,$dummy1,$ip21,$ip22,$ip23,$ip24,$dstPort,$dummy2,$flag,$seqb,$seqe,$size,$size1) = split(/[.:() ]/,$_);
  80. $sTime=join(".",$time1,$time2);
  81. # $dummy0="";
  82. $dummy1="";
  83. $dummy2="";
  84. $flag="";
  85. if ( ($seqe ne "ack") && ($seqb eq "")) {
  86.    $seqb=$seqe;
  87.    $seqe=$size;
  88.    $size=$size1;
  89. }
  90.         $prefixc=join(".",$ip11,$ip12);
  91. $prefixs=join(".",$ip21,$ip22);
  92. $src=join(".",$ip11,$ip12,$ip13,$ip14);
  93. $dst=join(".",$ip21,$ip22,$ip23,$ip24);
  94. $srcp=join(".",$ip11,$ip12,$ip13,$ip14,$srcPort);
  95.   $dstp=join(".",$ip21,$ip22,$ip23,$ip24,$dstPort);
  96.         $found=0;
  97.         foreach $j (0 .. $#ftpC) {
  98.         if ($src eq $ftpC[$j]) {
  99.                    $found=1;
  100. $client=$srcp;
  101. $server=$dstp;
  102.                 }
  103.         if ($dst eq $ftpC[$j]) {
  104.                    $found=1;
  105. $client=$dstp;
  106. $server=$srcp;
  107.                 }
  108.                          }
  109.        if ($found eq 0) { 
  110. print "ERROR in BW-seq-ftp.pl: $src $dstn";
  111.   }                     
  112.         #capture 3 types of packaets
  113. # 1. data packet to the server
  114. # 2. data packet from the server
  115. # 3. ack packet to the server
  116.         #data packet from ISI server
  117. if ( $prefixc eq $isiPrefix) {
  118. # if ($srcp eq $server) {
  119. if ( $seqe ne "ack" ) {
  120. # if ( $size eq 1460 ) {
  121. if ( $size >  1000 ) {
  122. print OUT "$client $server $seqe $sTime datan"
  123. }
  124.                 }
  125. }
  126. #ACK packet to ISI
  127. if ($prefixs eq $isiPrefix)  {
  128. if ($seqe eq "ack") {   
  129. print OUT "$client $server $size $sTime ackn"
  130. }
  131. else {
  132. # if ( $size eq 1460 ) {
  133. if ( $size > 1000 ) {
  134. print IN "$client $server $sTime $seqen";
  135. }
  136.                 }
  137. }
  138. }
  139. close(OUT);
  140. close(IN);