1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | #!/bin/bash ##################################### #This script for # #alive ip and show name # #uses module arping and work # #for this time only by Debian bases # ##################################### #GLOBAL VARIABLE LOGFILE=logping.log #LogFile ARPING="apt-get install arping" #Install arping HPING="apt-get install hping3" #Install hping3 ETH=$1 #Device Name IP=$(ifconfig $ETH | grep "inet addr" | cut -d":" -f2 | cut \ -d" " -f1 | cut -d"." -f1-3) #Found Ip #CREATE FUNCTION FOR READLINE readlines() { while read line; do ping=`ping -c 1 -b $line` && echo -e "\n**********************************************************************" echo "IP $line UP" `arp -i $ETH $line | grep ether | awk '{print "Name " $1 " With macaddr "$3}'` echo -e "\n" echo `hping3 -c 1 -i $ETH $line --scan 0-6000 -S |awk '{print $1}' 2>&1` done < $LOGFILE exit 1 } if [ -s "$LOGFILE" ] then rm $LOGFILE fi #DONE WITH FUNCTION #Check if corect start script #t.e. enter device name eth0 for example if [ $# -ne 1 ]; then echo "Usage - ./ping_and_scan.sh (Enter device like eth0)" exit fi #somtimes finction not work with #start with user privileg #next row check if script start #with user access if [ "$(id -u)" != "0" ]; then echo "This script must be run as root" 1>&2 exit 1 fi #For reason script work with #arping, check if pacckages instaled #if not it is installed with root access if [ "$(dpkg -s arping | grep 'Status: install ok' | cut -d" " -f3)" != "ok" ];then echo "packages arping is not installed - Packages Install " echo `$ARPING` && exit 1 fi if [ "$(dpkg -s hping3 | grep 'Status: install ok' | cut -d" " -f3)" != "ok" ];then echo "packages hping3 is not isntalled - Packages Install " echo `HPING` && exit 1 fi #Variable for Device #Check for ip address ping_scanning(){ for addr in $(seq 1 255); do arp_alive=`arping -c 1 $IP.$addr | grep "bytes from" |\ cut -d " " -f 5 | cut -d "(" -f 2 |\ cut -d ")" -f 1 1>&2 >> $LOGFILE &` done } ping_scanning echo "Arp is working Waiting " while true; do if ! pgrep arping > /dev/null; then readlines else echo -n "." fi sleep .3 done |
27.03.2015 г.
Check alive ip with bash file
26.03.2015 г.
Python script for search file type with options for deleted them
#########################################
# Script uses for deleted searched with#
# extension file!! #
#########################################
# --*-- coding: utf-8 --*--
import os, argparse, time
# parser = argparse.ArgumentParser(description='Process for deleted file')
# parser.add_argument('integers', metavar='N', type=int, nargs='+',
# help='an integer for the accumulator')
# args = parser.parse_args()
# print(args.accumulate(args.integers))
#Asking for Begin Dirname and search type
dirname = raw_input("Enter dirname from begin :")
Ending = raw_input("Enter exsension for deleted :")
acumulate_result = [] #Use for acumulate result if whant to deleted it
def Searc_Torrent(dirname):
"""Function use for search file with
with help module os.walk"""
if os.path.isdir(dirname) and os.path.exists(dirname):
for root, path, filename in os.walk(dirname):
for fn in filename:
if fn.endswith(Ending):
yield os.path.join(dirname,fn)
else:
print "\n%s is not looking by folder" % dirname
def show_torrent():
"""Function use for show result and add them to list
with name acumulate_result"""
begin = time.time()
for f in Searc_Torrent(dirname):
print f
acumulate_result.append(f)
ending = time.time()
print "Search finish with %s secund's" % (ending-begin)
def delete_result():
"""Function use for delete result"""
for deleted in acumulate_result:
yield deleted
if __name__ == "__main__":
show_torrent()
queston = raw_input("Do you whant to delete result ? (Y/N) :")
if queston.lower() == 'y':
print "Deleted"
for deleted in delete_result():
os.unlink(deleted)
elif queston.lower() == 'n':
print "Good bye"
else:
print "Good bye with wron answer!!!"
25.03.2015 г.
python script for search duplicated file
##################################################
# Search for duplicated files without, #
# meaningless file exstension #
# NOT EDIT BY HAND!!! #
##################################################
#IMPORT MODULES FOR SCRIPT
import hashlib, os, locale, fileinput, platform, logging
from itertools import *
from operator import itemgetter
#THIS USE FOR GIVE MD5 FOR FILE'S
md = hashlib.md5()
encoding = locale.getdefaultlocale()[1]
logging.basicConfig(filename='logfile.log', level=logging.DEBUG, \
format='%(message)s', filemode="w")
Dir = raw_input("Enter destination for begin use \\ : ")
extension = raw_input("Enter extension for file's : ")
#Dir = "C:\\script"
#extension = "py"
_File = [] #CONTAINED PATH FOR FILE
_File_H = [] #CONTAINED MD5 CODE FOR FILE
_duplicated = [] #CONTAINED DUPLIATED
_duplicated_sravnqva = [] #NEED FOR ZIP
subdirlist = [] #MAY DELETED IF YOU WON USED FOR FUNCTION search_file
one= [] #ADD FILEDPUPLICATES
two= [] #ADD MD5 FOR DUPLICATE FILE
#SEARCH WITH OS.LISTDIR NOT WORKING FOR MOMENT
# def search_file(Dir):
# for file in os.listdir(Dir):
# if os.path.isfile(file):
# yield os.path.join(Dir,file)
# else:
# subdirlist.append(os.path.join(Dir, file))
# try:
# for subdir in subdirlist:
# search_file(subdir)
# except:
# print "Somting wrong"
#SEARCH WITH OS.WALK
def search_os_walk(Dir):
for path,dirlist,filelist in os.walk(Dir):
for fn in filelist:
if fn.endswith("."+extension):
try:
yield os.path.join(path,fn)
except IOError, e:
print "Not allowed", e
#FUNCTION USE FOR ENCRIPT FILE TO MD5
def md_5(filePath):
try:
with open(filePath, 'rb') as fh:
m = hashlib.md5()
while True:
try:
data = fh.read(8192)
if not data:
break
m.update(data)
except IOError, e:
print "Not allowerd Basi", e
return m.hexdigest()
except IOError, e:
pass
#SEARCH FOR FILE AND APPEND THEM TO REQUIRED LIST (LOOKED ABOVE FOR DESCRIPTION'S )
for file in search_os_walk(Dir):
_File.append(file)
_File_H.append(md_5(file))
for f,z in (izip(_File, _File_H)):
if z in _duplicated:
_duplicated_sravnqva.append(z)
_duplicated.append(z)
print "*"*80
_Dupliated = [x[0] for x in zip(_File, _File_H) if x[1] in _duplicated_sravnqva]
for i in _Dupliated:
one.append(i)
two.append(md_5(i))
#RESULT IN DICTIONARI, NEEDED FOR FUNCTION GROUPBY
d = dict(zip(one,two))
di = sorted(d.iteritems(), key=itemgetter(1))
for k, g in groupby(di, key=itemgetter(1)):
#IF YOU WHANT TO SHOW IN COLUMN UNCHECK BOTTOM ROW'S
#~ for i,z in enumerate(map(itemgetter(0), g)):
#~ logging.info(str(i),(z))
info = map(itemgetter(0), g)
print "Duplicated ", info
logging.info(str(info))
print "\n"
answer = raw_input("Do you whant to view txt file with result (y/n) :")
if answer.lower() != 'y':
pass
else:
File = open('logfile.log')
for line in list(File.readlines()):
print line
23.03.2015 г.
Python use module logging to create log file.
import logging
import time
logging.basicConfig(filename='logfile.log', level=logging.DEBUG, \
format='%(asctime)s %(name)-5s %(levelname)-5s %(message)s', \
datefmt='%m-%d %H:%M')
def main():
try:
mathFail = 1/0
except Exception, e:
t=time.ctime()
logging.info(str(e))
if "__main__" == __name__:
main()
Add aliace to program for windows
WinButton+R - >regedit
HKEY_LOCAL_MACHINE
SOFTWARE
Microsoft
Windows
App Path
->Create new key in right windows in Default String post path to exe. In the same window create
new StringValu with name "Path" and post path to exe
HKEY_LOCAL_MACHINE
SOFTWARE
Microsoft
Windows
App Path
->Create new key in right windows in Default String post path to exe. In the same window create
new StringValu with name "Path" and post path to exe
21.03.2015 г.
Direct change file with python use with use fileinput
1 2 3 4 5 6 7 8 | import re import fileinput fname = "123.txt" #( file has line: Ala bala 123) for line in fileinput.FileInput(fname, inplace=1): line = re.sub(r'Ala bala \d{3}', "New Wine", line) print line |
Абонамент за:
Публикации
(
Atom
)