Skip to content

Instantly share code, notes, and snippets.

@tyr0chen
tyr0chen / wc.py
Created February 20, 2015 13:23
wc for python
import sys
totol_lines=totol_words=totol_characters=0
for loop in sys.argv[1:]:
pfile=open(loop,'rU')
lines=words=characters=0
for eve_line in pfile:
lines+=1
words+=len(eve_line.split())
characters+=len(eve_line)
print "%d\t%d\t%d\t%s"%(lines,words,characters,loop)
@tyr0chen
tyr0chen / random_mac.sh
Created February 20, 2015 13:09
generet random legel mac address
#!/bin/bash
#Description:this program automatically generates random legal mac address
#Ver.2.0 2014-10-26
#Author:Tyr
#Usage:./random_mac.sh [num]
i=0
while [ "$i" -lt "$1" ]
do
random=$(hexdump -n6 -e '/1 ":%02x"' /dev/urandom)
if echo $random | grep -q '*';then
@tyr0chen
tyr0chen / record-wan-ip.sh
Created February 20, 2015 12:59
record wan ip address for openwrt
#!/bin/ash
#description:log the daily pppoe-wan ip address
#2014-12-2
#Tyr
log_file=/mnt/sda3/log/wan-ip.log
. /lib/functions/network.sh
network_get_ipaddr ip wan
@tyr0chen
tyr0chen / catch-ps-of-adbyby.sh
Last active August 29, 2015 14:15
monitor ps of adbyby for openwrt.
#!/bin/bash
log_file=/mnt/sda3/log/adbyby.log
echo "
To:blog@chenhd.com
From:openwrt@chenhd.com
Subject:Netgear 3800 overload warning
I'm sorry to tell you the overload up to 5.
" > /tmp/mail.txt
@tyr0chen
tyr0chen / dnsmasq-config-for-gfw.sh
Created February 20, 2015 12:56
dnsmasq configuration for gfw,support google,facebook,twitter and youtube.
#Google and Youtube
server=/.google.com/127.0.0.1#5300
server=/.google.com.hk/127.0.0.1#5300
server=/.gstatic.com/127.0.0.1#5300
server=/.ggpht.com/127.0.0.1#5300
server=/.googleusercontent.com/127.0.0.1#5300
server=/.appspot.com/127.0.0.1#5300
server=/.googlecode.com/127.0.0.1#5300
server=/.googleapis.com/127.0.0.1#5300
server=/.gmail.com/127.0.0.1#5300
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define CANARY "in_the_coal_mine"
struct {
char buffer[1024];
char canary[sizeof(CANARY)];
} temp = { "buffer", CANARY };
@tyr0chen
tyr0chen / log-failure.sh
Last active August 29, 2015 14:15
analyse pam failure
#!/bin/bash
#description:log failure information
#2014-11-?
#2014-11-21 change:just send today log,not the whole log
cat /var/log/auth.log | grep failure >> /home/log/pam.failure
cat /var/log/auth.log | grep failure > /tmp/log/pam.failure
test=`cat /tmp/log/pam.failure`
if [ -n "$test" ];then
mutt -s "ECS-pam failure" mail@email.com < /tmp/log/pam.failure
fi
@tyr0chen
tyr0chen / serverlog.sh
Last active August 29, 2015 14:15
server log information
#!/bin/bash
#description:analyse web server log.
#ver 0.1
#2014/11/20 Tyr analyse auth,message,apache,ssh,vsftpd
echo "
"
echo -e "=======================系统信息===========================
内核版本: `uname -a`
CPU信息: `cat /proc/cpuinfo | egrep "model name|cpu MHz|Processor"|cut -d : -f2`
#!/bin/bash
#=================匹配样式===============
pattern="^Internet Explorer [0-9]+$|^Windows Server (2003|2008|2008 R2|2012 and Windows Server 2012 R2)$|^Windows Vista$|^Windows 7$|^Windows 8 and Windows 8.1$|^Server Core installation option$|^ASP.NET MVC [2-5]\.[0-1]$|^Microsoft Office 20(07|10)$|^Microsoft Office for Mac$|^Other Microsoft Office Software$|^Microsoft SharePoint Server 2010$|^Microsoft Office Web Apps 2010$|^Microsoft Word Viewer$|^Microsoft Office Compatibility Pack Service Pack 3$|^Microsoft SharePoint Server 2010 Service Pack 2$"
#将完整的目录拆分为按照MS14-0XX来保存
for ((ci=56;ci<=79;ci++))
do
if [ "$ci" -eq "74" ];then #微软没有给MS14-075补丁,所以跳过这个
cat /home/ms-all | sed -n "/MS14-074/,/MS14-076/p" > /home/ms/MS14-074
ci=75
@tyr0chen
tyr0chen / install-asciiauarium.sh
Last active August 29, 2015 14:15
This script will automatically install asciiauarium
#!/bin/bash
#description:auto-install scripts for asciiquarium.
#asciiquarm author is http://robobunny.com/wp/
#2014-11-22
#scripts writed by Tyr (http://tyr.so)
do_exit() {
cp $logfile $HOME/install_asciiquarium.log
rm $HOME/asciiquarium -rf
echo "
sorry install failed!