Michelebuffa

Telnet_CPE_login

Sep 18th, 2020
862
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <WiFi.h>
  2. #include "TelnetClient.h"
  3.  
  4. const char* user = "utente";
  5. const char* pwd = "utente";
  6.  
  7. char* ssid     = "Michele";
  8. char* password = "pswWifi";
  9.  
  10. WiFiClient client;
  11. telnetClient tc(client);
  12.  
  13.  
  14. //put here your router's ip address
  15. IPAddress mikrotikRouterIp (192, 168, 22, 1);
  16.  
  17. void setup () {
  18.   Serial.begin(115200);
  19.   Serial.print("\nConnecting to ");
  20.   Serial.println(ssid);
  21.  
  22.   WiFi.begin(ssid, password);
  23.  
  24.   while (WiFi.status() != WL_CONNECTED) {
  25.     delay(500);
  26.     Serial.print(".");
  27.   }
  28.   Serial.println("\nWiFi connected");
  29.   Serial.println("IP address: ");
  30.   Serial.println(WiFi.localIP());
  31.  
  32.   //WICH CHARACTER SHOULD BE INTERPRETED AS "PROMPT"?
  33.   tc.setPromptChar('>');
  34.  
  35.   //this is to trigger manually the login
  36.   //since it could be a problem to attach the serial monitor while negotiating with the server (it cause the board reset)
  37.   //remove it or replace it with a delay/wait of a digital input in case you're not using the serial monitors
  38.   char key = 0;
  39.   Serial.println("\r\npress Enter to begin:");
  40.   do {
  41.     key = Serial.read();
  42.   } while (key <= 0);
  43.  
  44.   //PUT HERE YOUR USERNAME/PASSWORD
  45.   if (tc.login(mikrotikRouterIp, user, pwd)) {      //tc.login(mikrotikRouterIp, "admin", "", 1234) if you want to specify a port different than 23
  46.     tc.sendCommand("ip");
  47.     tc.sendCommand("address");
  48.     tc.sendCommand("print");
  49.     Serial.println("login correct");
  50.   }
  51.   else {
  52.     Serial.println("login failed");
  53.   }
  54.   tc.disconnect();
  55. }
  56.  
  57. void loop () {                                         //  run your loop routine
  58. }
RAW Paste Data