Skip to content

Instantly share code, notes, and snippets.

@hinklefoxmail hinklefoxmail/ Secret
Created Sep 3, 2017

What would you like to do?
IP Shutdown
function checkIps() {
//Get sheet
var ss = SpreadsheetApp.openById('1gufH3xiGZGdnzbyZkh_tkjPh98d8RZ6DO7NInAj2lDo');
var sheet = ss.getSheetByName('info');
var exportSheet = ss.getSheetByName('IP Activity');
//get start and end times
var lastRunMs = sheet.getRange(1, 2).getValue();
var lastRun = new Date(lastRunMs);
var now = new Date();
sheet.getRange(1, 2).setValue(now.getTime()-2800000);
var startTime = lastRun.toISOString();
var endTime = now.toISOString();
//get report logs
var page = AdminReports.Activities.list('all', 'login', {
startTime: startTime,
endTime: endTime,
maxResults: 500,
//if page items is empty update sheet
var items=page.items;
exportSheet.appendRow(['No Logins'])
//otherwise add ips
var noSus = true;
for (var i = 0; i < items.length; i++){
var email = items[i];
var ip = items[i].ipAddress;
if (ip != ''){
exportSheet.appendRow([email, ip]);
var noSus = false;
if (noSus){
exportSheet.appendRow(['Only School IPs'])
//every day checks if important accounts are 2 step verified and writes the results to a spreadsheet
function check2step(){
var ss = SpreadsheetApp.openById('1gufH3xiGZGdnzbyZkh_tkjPh98d8RZ6DO7NInAj2lDo');
var sheet = ss.getSheetByName('Important Accounts');
var data = sheet.getDataRange().getValues();
for(var i=1; i<data.length; i++){
var email = data[i][0];
var user = AdminDirectory.Users.get(email);
sheet.getRange(i+1, 2).setValue(user.isEnrolledIn2Sv);
//checks if an account is 2 step verified using the sheet in check2step and shuts down the account if it is not
function suspendAccount(email){
var ss = SpreadsheetApp.openById('1gufH3xiGZGdnzbyZkh_tkjPh98d8RZ6DO7NInAj2lDo');
var sheet = ss.getSheetByName('Important Accounts');
var export = ss.getSheetByName('lockdown');
var data = sheet.getDataRange().getValues();
var foundAccount = false;
for (var i = 0; i < data.length; i++){
if (email == data[i][0]){
foundAccount = true;
var is2step = data[i][1];
Logger.log(email+' is 2 step');
return foundAccount;
var resource = {suspended: true}
AdminDirectory.Users.update(resource, email);
export.appendRow([email, 'Suspended for suspicious IP'])
MailApp.sendEmail('', 'Account Suspended', email+' has been suspended.');
Logger.log(email+' has been suspended');
return foundAccount;
Logger.log('The account was not found');
return foundAccount;
function testSus(){
var email = '';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.