Guest User

Untitled

a guest
Jul 17th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3.  
  4. //Delay between Dynamic IP updates, in minutes...
  5. int UpDelay = 1;
  6.  
  7. //DNS Server to update
  8. char DNS_Server[] = "dynamicdns.park-your-domain.com";
  9.  
  10. //MAC address
  11. byte mac[] = { 0x90, 0xA1, 0xDB, 0x02, 0x05, 0x17 };
  12. //Public IP server
  13. char IPServer[] = "checkip.dyndns.com";
  14. //checkip.dyndns.org
  15.  
  16.  
  17. //Ignore these
  18. String IPA, OldIPA;
  19.  
  20. EthernetClient client;
  21.  
  22. void setup() {
  23. Serial.begin(19200);
  24. Serial.println("Started...");
  25.  
  26. //Turn LED
  27.  
  28. Configure:
  29. Serial.print("(please wait)\nEthernet ");
  30. if (Ethernet.begin(mac) == 0) {
  31. Serial.println("Configuration failed. Retrying in 2 minutes.");
  32. delay(60*1000*2);
  33. goto Configure;
  34. }
  35. Serial.println("Configured...");
  36. //Turn LED 2 on
  37. delay(5000);
  38. }
  39.  
  40. void loop() {
  41. Serial.println("Running Update");
  42. Serial.println("Attempting Connect.");
  43. if(client.connect(IPServer, 80)){
  44. Serial.println("Connected to IP Server\n\n");
  45.  
  46. client.println("GET HTTP/1.0");
  47. client.println();
  48.  
  49. //Wait for response
  50. delay(2000);
  51.  
  52. String BufLine;
  53. while(client.available() > 0){
  54. BufLine += client.read();
  55. if(BufLine.endsWith("\n")){
  56. if(BufLine.indexOf("Current IP Address: ") > -1){
  57. IPA = BufLine.substring(76,BufLine.length()-16);
  58. Serial.println(IPA);
  59. client.stop();
  60. if(IPA != "0"){
  61. delay(2000);
  62. //UPDATE DNS HERE
  63. Serial.println("Time to.");
  64. EthernetClient client;
  65. delay(2000);
  66. if(client.connect(DNS_Server, 80)){
  67. Serial.println("Updating DNS");
  68. long time = (millis()/1000);
  69. String sendstring = "GET /update?host=www&domain=cluelessperson.com%20&password=2e7958b8d7304f978b7cc01ef18925c3&Timer=" + String(time) + " HTTP/1.0";
  70. client.println(sendstring);
  71. client.println("");
  72.  
  73. for(int x = 0;x < 10;x++){
  74.  
  75. while(client.available() > 0){
  76. Serial.print(client.read());
  77. }
  78. delay(1000);
  79. }
  80. client.stop();
  81. }else{
  82. Serial.println("Failed to connect to dns server");
  83. }
  84.  
  85.  
  86. }
  87. OldIPA = IPA;
  88. }
  89. BufLine = "";
  90.  
  91. }
  92. }
  93. Serial.print("\n\n");
  94. }else{
  95. Serial.println("Connection failed...");
  96. //Turn Update Light Off
  97. }
  98. for(int i = (30*UpDelay);i > -1 ;i--){
  99. delay(1000);
  100. Serial.println(i);
  101. }
  102. }
Add Comment
Please, Sign In to add comment