Code:
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
Channel channel = session.openChannel("shell");
channel.connect();
Expect expect = new ExpectBuilder()
.withOutput(channel.getOutputStream())
.withInputs(channel.getInputStream())
.withEchoInput(System.out)
.withEchoOutput(System.err)
//.withInputFilters(removeColors(), removeNonPrintable())
.withExceptionOnFailure()
//.withLineSeparator("\r")
.build();
try {
expect.expect(regexp("@.*] >"));
expect.sendLine("/ip dhcp-client set use-peer-dns=no numbers=0");
expect.expect(regexp("@.*] >"));
expect.sendLine("/ip dns set servers=8.8.8.8,1.1.1.1");
expect.expect(regexp("@.*] >"));
expect.sendLine("/ip dns set allow-remote-requests=no");
expect.expect(regexp("@.*] >"));
expect.sendLine("/ip proxy set enabled=no");
expect.expect(regexp("@.*] >"));
expect.sendLine("/system clock set time-zone-autodetect=no time-zone-name=America/Puerto_Rico");
expect.expect(regexp("@.*] >"));
expect.sendLine("/system ntp client set enabled=yes primary-ntp=74.85.156.1 secondary-ntp=74.85.156.2");
expect.expect(regexp("@.*] >"));
expect.sendLine("/snmp community set [ find default=yes ] name=4ll13d");
expect.expect(regexp("@.*] >"));
expect.sendLine("/snmp set contact=Fusetelecom");
expect.expect(regexp("@.*] >"));
} finally {
expect.close();
channel.disconnect();
session.disconnect();
}