Skip to content

Instantly share code, notes, and snippets.

View digizeph's full-sized avatar
🌟

Mingwei Zhang digizeph

🌟
View GitHub Profile
@digizeph
digizeph / create_users.sh
Created April 21, 2015 00:15
Copy two columns from the Google Sheet, users and key. Then replace all the '\t' with '='. Name it as credentials.txt. Run this script. It should create the users for you.
#!/bin/bash
while IFS='=' read USER KEY
do
if [ ! -d "/home/$USER" ]; then
sudo useradd -m $USER -g snal
echo created user $USER
sudo su - $USER -c "mkdir /home/$USER/.ssh; echo $KEY > /home/$USER/.ssh/authorized_keys; chmod 600 /home/$USER/.ssh/authorized_keys"
else
echo $USER already created
@digizeph
digizeph / get_logins.sh
Created April 23, 2015 05:54
Question: write a script to check who has logged in into your machine in the past month and log this information (usernames and last login) to a file.
#!/bin/bash
onemonth=`date --date="1 month ago" +"%y%m%d"`
last -F -R| head -n -2| cut -c1-9,27-46 | grep -v "reboot"| while read line; do date=`date -d "$(echo $line | awk '{ print $2" "$3" "$4" "$5 }')" +"%y%m%d"`; [[ $date -ge "$onemonth" ]] && echo $line; done > output.txt
@digizeph
digizeph / pom.xml
Created April 27, 2015 23:31
pom for building snal monitor
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cis-snal</groupId>
<artifactId>status-keeper</artifactId>
<version>1.0-SNAPSHOT</version>
#!/bin/bash
####
## read in fields
####
echo "Title:"
read -e title
echo ""
prefix length rib entries count
0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 17
@digizeph
digizeph / PlainGraph.java
Created August 25, 2015 19:14
Simple graph visualization using graphstream library.
package visualization;
import org.graphstream.graph.Graph;
import org.graphstream.graph.Node;
import org.graphstream.graph.implementations.SingleGraph;
import java.util.Iterator;
public class PlainGraph {
public static void main(String args[]) {
m count
8 17
9 5
10 36
11 92
12 239
13 418
14 908
15 1436
16 9984
@digizeph
digizeph / gist:b0c0debee268cb70c4da
Created September 2, 2015 02:27
IPv6 table dump prefix lengths count. RouteViews3 rib.20150901.0200.bz2
/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/bin/java -Xmx2g -Didea.launcher.port=7536 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 14.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/lib/tools.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/jre/lib/jce.jar:
@digizeph
digizeph / freebsd_virtualbox_message.txt
Created October 30, 2015 18:27
The installation messages of VirtualBox on FreeBSD.
Message from virtualbox-ose-4.3.32:
=============================================================================
VirtualBox was installed.
You need to load the vboxdrv kernel module via /boot/loader.conf:
vboxdrv_load="YES"
You also have to add all users to your vboxusers group in order to use vbox.
@digizeph
digizeph / Whois.java
Created November 6, 2015 17:58
whois api usage example.
package bgpi.utils.whois;
import bgpi.utils.io.Output;
import org.apache.commons.net.whois.WhoisClient;
import java.io.IOException;
/**
* Created by Mingwei on 10/8/15.
* <p>