Created
February 10, 2018 01:45
-
-
Save picatz/8f2fdfe6ab011f7fa1af045f517b81e3 to your computer and use it in GitHub Desktop.
example client-side javascript code to communicate with bettercap API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var session | |
var credentials | |
var resp | |
function encodeBasicAuthorizationCredentials(options = {}) { | |
return 'Basic ' + btoa(options.username + ":" + options.password) | |
} | |
function setCredentials(options = {}) { | |
credentials = encodeBasicAuthorizationCredentials(options) | |
} | |
function getSession() { | |
fetch("/api/session", { method: 'GET', headers: { 'Authorization': credentials } }) | |
.then(function(response) { | |
response.json().then(function(json) { session = json }) | |
}); | |
} | |
function setSession(data) { | |
var request = new Request("/api/session", { | |
method: 'POST', | |
body: JSON.stringify(data), | |
headers: { | |
'Authorization': credentials | |
} | |
}); | |
fetch(request).then(function(response) { | |
response.json().then(function(json) { resp = json }) | |
}); | |
} | |
setCredentials({ username: "bcap", password: "bcap" }) | |
data = {"cmd":"net.probe on"} | |
setSession(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment