Advertisement
3ddavid

3ddavid-code

Jan 16th, 2012
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. 3ddavid-code
  2. #!/usr/bin/perl -w
  3.  
  4. #
  5. #Simple perl script to parse pastebin to alert on keywords of interest.
  6. #1)Install the the LWP and MIME perl modules
  7. #2)Create two text files one called keywords.txt and tracker.txt
  8. #2a)keywords.txt is where you need to enter keywords you wish to be alerted on, one per line.
  9. #3)Edit the code below and enter your smtp server, from email address and to email address.
  10. #4)Cron it up and receive alerts in near real time
  11. #
  12.  
  13.  
  14. use LWP::Simple;
  15. use LWP::UserAgent;
  16. use MIME::Lite;
  17. MIME::Lite->send('smtp','#enter_email_server_here', Timeout=>60);
  18.  
  19. my $ua = new LWP::UserAgent;
  20. $ua->agent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1");
  21.  
  22. my $req = new HTTP::Request GET => 'http://pastebin.com/archive';
  23. my $res = $ua->request($req);
  24. my $pastebin = $res->content;
  25.  
  26. #date
  27. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
  28. my $datestring = sprintf("%4d-%02d-%02d",($year + 1900),($mon+1),$mday-1);
  29. my $dir = sprintf("%4d-%02d",($year + 1900),($mon+1));
  30.  
  31. #
  32. open (MYFILE, 'keywords.txt');
  33. my @keywords = <MYFILE>;
  34. chomp(@keywords) ;
  35. my $regex = join('|', @keywords);
  36.  
  37.  
  38.  
  39. my $tracking_file = 'tracker.txt';
  40.  
  41. my @links = getlinks();
  42.  
  43. if (@links) {
  44. foreach $line (@links){
  45. if (checkurl($line) == 0){
  46. my $request = "http://pastebin.com/$line\n";
  47. my $link = $line;
  48. my $req = new HTTP::Request GET => "$request";
  49. my $res = $ua->request($req);
  50. my $content = $res->content;
  51. my @data = $content;
  52. foreach $line (@data){
  53. if ($content =~ m/\<textarea.*?\)\"\>(.*?)\<\/textarea\>/sgm){
  54. @data = $1;
  55. foreach $line (@data){
  56. if ($line =~ m/($regex)/i){
  57. storeurl($link);
  58. print "$request $line\n";
  59. my $msg = MIME::Lite->new(
  60. From => '#enter from address',
  61. To => '#enter to address;',
  62. Cc => '',
  63. Subject => "Keyword Detected ($1) $request",
  64. Type => 'multipart/mixed',
  65. Data =>"",
  66. );
  67. $msg->attach(
  68. Type => 'TEXT',
  69. Data => "\n\n$line\n\n",
  70. );
  71. $msg->send;
  72. }
  73. }
  74. }
  75. }
  76. }
  77. }
  78. }
  79.  
  80.  
  81. sub getlinks{
  82. my @results;
  83. if (defined $pastebin) {
  84. @data = $pastebin;
  85. foreach $line (@data){
  86. while ($line =~ m/\"icon\"\>\<a\shref\=\"\/(.*?)"\>/g){
  87. my $url = $1;
  88. push (@results, $url);
  89. }
  90. }
  91. }
  92.  
  93. return @results;
  94. }
  95.  
  96. sub storeurl {
  97. my $url = shift;
  98. open (FILE,">> $tracking_file") or die("cannot open $tracking_file");
  99. print FILE $url."\n";
  100. close FILE;
  101. }
  102.  
  103. sub checkurl {
  104. my $url = shift;
  105. open (FILE,"< $tracking_file") or die("cannot open $tracking_file");
  106. foreach my $line ( <FILE> ) {
  107. if ( $line =~ m/$url/i ) {
  108. return 1;
  109. }
  110. }
  111. return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement