Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. use LWP::UserAgent;
  2.  
  3. my $hostout = `curl http://ifconfig.me/ip`; #адрес нашего роутера
  4.  
  5. if ($hostout =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/) {
  6. my $ip = "$1.$2.$3.$4";
  7.  
  8. #Добавлено:
  9. open (FILE,"my_ip.txt");
  10. my @lines = <FILE>;
  11. $old_ip = $lines[0]; #Считываем IP из файла
  12. $old_ip =~ s/^\s+|\s+$//g; #trim
  13. close(FILE);
  14. if ($old_ip eq $ip) {
  15. die "IP not changed"; # Выходим из скрипта, если IP не изменился
  16. }
  17. open (FILE,">my_ip.txt");
  18. print FILE $ip; # Записываем в файл новый IP
  19. close(FILE);
  20.  
  21. my $token = "f5716bb71da669f414b1b29e7f26027bcc51cb784780b5444066b8a3";
  22. my $domain00 = "fisab.ru";
  23. my $id00 = "32357995";
  24. my $subdomain01 = "www";
  25. my $id01 = "32357995";
  26. my $url00 ="https://pddimp.yandex.ru/nsapi/edit_a_record.xml?token=$token&domain=$domain00&record_id=$id00&content=$ip";
  27. my $url01 ="https://pddimp.yandex.ru/nsapi/edit_a_record.xml?token=$token&domain=$domain00&subdomain=$subdomain01&record_id=$id01&content=$ip";
  28.  
  29. my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0 } );
  30.  
  31. my $response = $ua->get($url00);
  32. if ( $response->is_success ) {
  33. print $response->decoded_content;
  34. } else {
  35. die $response->status_line;
  36. }
  37.  
  38. my $response = $ua->get($url01);
  39. if ( $response->is_success ) {
  40. print $response->decoded_content;
  41. } else {
  42. die $response->status_line;
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement