Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script Auto Login Wifi.id dengan ESP8266
#include <ESP8266WiFi.h>
#include <ESP8266Ping.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecureBearSSL.h>
/*
* Script Auto Login Wifi.id dengan menggunakan ESP8266
* Script ini di buat oleh Akbar Yahya, pakai boleh di jual jangan!
*/
const char* ssid = ""; //nama wifi
const char* password = ""; //password wifi
String user_id = ""; //id wifi_id
String pass_id = ""; //pass wifi_id
String ipgate = ""; //ini gak wajib, ini ip yang pernah terknonek ke router ke modem telkom
String induk = "WAG-D7-BAL"; //ini wajib, ini nama kota box yang ada di luar jalan
String setmac = ""; //ini gak wajib, ini mac router kamu yang konek ke bot auto konek
String wlan = ""; //ini gak wajib, ini kalau gak salah nama box kota yang ada di tiang
const char* hostName = "www.google.com"; //ini ping buat cek jaringan
bool cekwifi = true; //wajib kasih aktif kalau emang ada wifi_id :p
void setup() {
Serial.begin(115200);
Serial.println("");
Serial.println("Bot mencoba masuk ke ");
Serial.println(ssid);
WiFi.begin(ssid, password);
int i = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(++i); Serial.print(' ');
}
Serial.println('\n');
Serial.println("Konek ke wifi stabil dengan detail: ");
Serial.println("IP: " + String(WiFi.localIP().toString()) + " | IP GW: " + String(WiFi.gatewayIP().toString()) + " | MAC GW: " + WiFi.BSSIDstr() + " | RSSI: " + String(WiFi.RSSI()) + " | MAC: " + String(WiFi.macAddress().c_str()));
}
void loop() {
//cek ping
delay(1000);
int pingResult = Ping.ping(hostName);
if (pingResult) {
Serial.print("Ping ");
Serial.print(Ping.averageTime());
Serial.println("ms");
//ping normal lanjut send data di sini
} else {
if (cekwifi) {
Serial.println("Mulai cek login!!!");
String cek = UrlGet("https://welcome2.wifi.id/authnew/login/check_login.php?ipc=" + ipgate + "&gw_id=" + induk + "&mac=" + setmac + "&redirect=http://www.msftconnecttest.com/redirect&wlan=" + wlan + "", "username=" + user_id + "@spin2&password=" + pass_id + "");
if (cek == "-1") {
Serial.println("Salah Config Coba Tanya Mbak Google");
delay(60000);
} else if (cek.indexOf("Login Gagal") > 0) {
Serial.println("Login gagal gan");
delay(10000);
} else if (cek.indexOf("User already Expired") > 0) {
Serial.println("Beli sana voc lagi wkwkwk");
delay(60000);
} else if (cek.indexOf("Login Sukses") > 0) {
Serial.println("Lanjut Gan");
} else if (cek.indexOf("Invalid") > 0) {
Serial.println("Password/username nya salah cong...");
delay(60000);
} else {
Serial.println("Indihomonya lagi jelek");
Serial.println(cek);
delay(5000);
}
} else {
Serial.println("Lapor pak RT Internetnya mati pak");
delay(20000);
}
}
}
String UrlGet(String hostGet, String data) {
int httpCode = 0;
std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure);
client->setInsecure();
HTTPClient https;
if (https.begin(*client, hostGet)) {
https.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36");
Serial.println("Curl....");
if (data == "") {
httpCode = https.GET();
} else {
https.addHeader("Content-Type", "application/x-www-form-urlencoded");
httpCode = https.POST(data);
}
if (httpCode > 0) {
if (httpCode == HTTP_CODE_OK) {
String payload = https.getString();
https.end();
return payload;
}
} else {
Serial.printf("Curl failed, error: %s\n\r", https.errorToString(httpCode).c_str());
}
https.end();
} else {
Serial.printf("Curl unable to connect\n\r");
}
return String(httpCode);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment