Part – I
By Suraj Singh Bisht
[email protected] www.bitforestinfo.com
1. Overview
................................... ................ ......................... ...... 03
2. What is Ping Scan ................................. ................................. 04 3. Why Create Ping Sweep Script ...................... 0 4. !ind "ive Syste# .................................. .................................. 0$ ................................. 0$ ................................. .................................. .................. ................ 0$ .................................. ................ .................... .. 0$ . Create Ping Sweep Script ................. .......................... ......... 0( .............................. .............................. .............................. ................ .............. .............................. ................ .............. .............................. ................ .............. ......................
0( 0( 0) 0* 0*
$. Ping Sweep C%des .................................. .................................. 10 (. H%w ,% se It ..................................... ..................................... 14 ). C%nc&si%n .................. ..................................... ...................... ... 1 *. /%&t e .......................................... .......................................... 1$ 10. %& Can !%%w s ................................ ................................ 1(
,his Paper is created +%r pr%viding a +ree t&t%ria %n Pyth%n /%&t H%w We Can Create Pyth%n Script ,hat Can Ping ari%&s Syste#s /&t%#aticay. In Si#pe W%rds Ping Sweeping is a set %+ pr%ced&re t% !ind Onine /vaiae achine in Speci+ic 'etw%r5. '%w "et /sse I+ %& Want ,% Scan 6ig "ist O+ IP /ddresses ,% !ind "ive H%st Syste#s 6&t this Pr%ced&re is very ti#e-c%nsing. S% here we can &se %&r a&t%#atic ping sweeping pyth%n script that can hande a %&r w%r5s a&t%#aticay.
S% In ,his Paper I a# g%ing t% exp%re e%w p%ints. 1. What is Ping Scan7 2. H%w t% !ind "ive Syste#s7 3. H%w t% Create Ping Sweep Script7
Ping Scan is a pr%cess %+ sending ICP 8CHO re9&est pac5et t% any ive h%st. I+ a H%st wants t% #enti%n his avaiaiity it wi de+initey repy with an ICP 8CHO resp%nse pac5et. '%w y%& wi thin5 why I said : previ%&s ines.
in
,his Is 6eca&se ,% Prevent Syste# !r%# Hac5ings /ttac5s sers se !irewas /nd Other Sec&rity !eat&res ,hat
%n
In /n%ther w%rd Ping Scans /s% @n%wn /s Ping Sweeping. Ping Sweeping is the pr%ced&re t% !ind %re ,han One achine /vaiaiity in Speci+ic 'etw%r5 =ange.
"et /sse I+ %& Want ,% Scan 6ig "ist O+ IP /ddresses ,% !ind "ive H%st Syste#s 6&t this Pr%ced&re is very ti#e c%nsing /nd %& d%n?t have that #&ch ti#e. S% here what we can d%7 we can &se %&r a&t%#atic ping sweeping pyth%n script that can hande a %&r w%r5s a&t%#aticay. In Si#pe W%rds ,his Script as% pays very i#p%rtant r%e in the vari%&s type %+ penetrating testing and hac5ing.
,% Send / Si#pe ICP 8ch% =e9&est y%& can &se #any types %+ &tiities in di++erent sit&ati%ns i5e
•
Here -n argent is seecting a ner %+ ti#e t% send ICP 8CHO re9&est.
$ ping -n 5 192.168.1.101/24
•
Here -n argent is seecting a ner %+ ti#e t% send ICP 8CHO re9&est.
$ ping -c 5 192.168.1.101/24
You can use regular open source tool called Nmap. Best For You For Scanning Because Nmap has also the ability to guess host even after ICMP lter and Fire!all. "ype "ype the follo!ing command to run ICMP IP Scan# $ nmap -sP -PI 192.168.1.101/24
!riends 6eive e ,his Script is very as% very g%%d exa#pe %+ #&ti-pr%cessing eca&se here in this script t% increase the speed %+ ping sweeping pr%cess we wi &se #&tipr%cessing #%d&e. n%w et
C%##and Seecting !&ncti%n setD%sDc%##andAse+BE setD%sDc%##andAse+BE %per F pat+%r#.syste#AB pat+%r#.syste#AB A%perFF :Wind%ws: :Wind%ws: BE ping F :ping -n GH GH: :ping A%perFF :"in&x: :"in&x: BE BE pingF :ping -c GH GH: :ping E pingF :ping -c GH GH: :ping se+.c%##adFping
!&ncti%n +%r Chec5ing IP Stat&s chec5pingAse+4 ipBE pingFse+.c%##ad recvF%s.p%penAping.+%r#at recvF%s.p%pe nAping.+%r#atAse+.ti#e%& Ase+.ti#e%&t4 t4 ipBB.readAB recvFrecv.&pperAB recv.c%&ntA <,,"< BE <,,"
8xtracting 'er +%r#at extracti%nAp%rtBE st%rep%rtFK 3eri+iying P%rt 3a&e p%rtE 3eri+ying P%rt is in =ange :-: p%rt :: p%rtE x1x2Fp%rt.spitA <-< <-
8xtracting Ip /ddress IPDextract%rAipBE st%re%FK ipFip.spitA
st%re%
!&ncti%n !%r 1&tiDpr%cessing scanningD%%stersAse+BE pr%cesFK ip se+.targetE 5FenA#&tipr%cessing.activeDchidrenABB 5FFse+.threadE ti#e.seepA3 ti#e.seepA 3B se+.threadFse+.threadJ 30 #ythreadF#&tipr%cessing #ythreadF#& tipr%cessing.Pr%cessAtar .Pr%cessAtargetFse+.chec getFse+.chec5ping 5ping argsFAipBB #ythread.startAB pr%ces.appendA#ythreadB #ythread pr%cesE #ythread.%inAB se+.ti#ec%seFti#e.ti#eAB se+.sh%wingDres&tsAB
'%w et #e share with y%& #y c%#pete c%des.
Here it
Q&srQ0inQpyth%n
# ---------------- READ ME --------------------------------------------# This Script is Created Only For Practise And Educational Purpose Only # This Script Is Created For http:!it"orestin"o!lo$spotco% # This Script is &ritten 'y __author__=''' __author__=''' ###################################################### By S.S.B Group ######################################################
Suraj Singh Admin S.S.B Group surajsinghbisht054@gmail.om http!""bitor$stino.blogspot.in"
%ot$! &$ $$l (roud )o B$ *ndian ###################################################### ''' # (((((((((((((((((Other Con"i$uration(((((((((((((((( # )sa$es : usag$ = +usag$! = +usag$! ,prog -options + # *ersion /$rsion=+,prog /$rsion= +,prog 0.0.+ # ((((((((((((((((((((((((((((((((((((((((((((((((((((
# I%portin$ Modules multipro$ssing1 tim$1 optpars$1 platorm import os1 multipro$ssing1
# Main En$ine class (ing$r! def __init__2s$l1 targ$t1 thr$ad1 output1 tim$out3! s$l.tim$start$d=tim$.tim$23 s$l.li$_ip_oll$tor=multipro$ssing.u$u$23 s$l.targ$t=targ$t s$l.thr$ad=thr$ad s$l.output=output s$l.tim$out=tim$out s$l.s$t_os_ommand23 #sel"chec+pin$, s$l.sanning_boost$rs23
# Sa.in$ O)tput sa$_output2s$l3! def sa$_output2s$l3! =op$n2s$l.output1'a' =op$n2s$l.output1 'a'3 3 s$l.li$_ip_oll$tor! for i in s$l.li$_ip_oll$tor! .6rit$2i7'8n' .6rit$2i7 '8n'3 3 .los$23 return
# Function For Multi/processin$ def sanning_boost$rs2s$l3! pro$s=- for ip in s$l.targ$t! 9=l$n2multipro$ssing.ati$_hildr$n233 9==s$l.thr$ad! if 9==s$l.thr$ad! tim$.sl$$p2: tim$.sl$$p2 :3 s$l.thr$ad=s$l.thr$ad7 :0 s$l.thr$ad=s$l.thr$ad7:0 mythr$ad=multipro$ssing mythr$ad=mu ltipro$ssing.(ro$ss2tar .(ro$ss2targ$t=s$l.h$ g$t=s$l.h$9ping1 9ping1 args=2ip133 mythr$ad.start23 pro$s.app$nd2mythr$ad3
for mythr$ad in pro$s! mythr$ad.join23 s$l.tim$los$=tim$.tim$23 s$l.sho6ing_r$sults23 return # Printin$ Function def sho6ing_r$sults2s$l3! stor$ip=- ;= ;= ;==! while ;== try! stor$ip.app$nd2s$l.li$_ip_oll$tor.g$t_no6ait233 except! ;=;7 ;=;7 s$l.li$_ip_oll$tor=stor$ip +8n+< <:1+#+ +#+< <0 print +8n+ print +-7 San Start$d >n 8t8t!8t+ 1tim$.tim$2s$l.tim$start$d3 print +-7 San ?los$d >n 8t8t!8t+ 1tim$.tim$2s$l.tim$los$3 print +-7 San )otal uration 8t!8t+ 1s$l.tim$los$s$l.tim$start$d print +-7 )otal i$ Syst$m Ans6$r$d8t!8t+ 1l$n2s$l.li$_ip_oll$tor3 if s$l.output! s$l.sa$_output23 print +8n-7 )han9s or Csing Dy (rogram. By S.S.B+ return
# Co%%and Selectin$ Function s$t_os_ommand2s$l3! def s$t_os_ommand2s$l3! op$r = platorm.syst$m23 platorm.syst$m23 2op$r== +&indo6s+3! 3! if 2op$r==+&indo6s+ ping = +ping n EF EF+ 2op$r== +inu;+3! 3! elif 2op$r== +inu;+ ping= +ping ping= +ping EF EF+ else ! ping= +ping ping= +ping EF EF+ s$l.ommad=ping return
# Function "or Chec+in$ IP Status def h$9ping2s$l1 ip3! ping=s$l.ommad r$=os.pop$n2ping.ormat r$=os.pop$ n2ping.ormat2s$l.tim$ou 2s$l.tim$out1 t1 ip33.r$ad23 r$=r$.upp$r23 r$.ount2 '))'3! 3! if r$.ount2'))' print +-78t EF 8t==gtH i$ + .ormat2ip3 s$l.li$_ip_oll$tor.put2ip3 return
# E0tractin$ 1u%!er "or%at $;tration2port3! def $;tration2port3! stor$port=- # *eri"iyin$ Port *alue if port! # *eri"yin$ Port is in Ran$e if ++ in port and +1+ not in port! ;1;I=port.split2'' ;1;I=port.split2 ''3 3 stor$port=rang$2int2;31int2;I33 # *eri"yin$ Port is in Co%%as elif +1+ in port and ++ not in port! stor$port=port.split2'1' stor$port=port.split2 '1'3 3 elif +1+ in port and ++ in port! ;I=- for i in port.split2'1' port.split2 '1'3! 3! if '' in i! y1yI=i.split2'' y1yI=i.split2 ''3 3 ;I=;I7rang$2int2y31int2yI33 else ! ;I.app$nd2i3 stor$port=;I else ! stor$port.app$nd2port3 else! pass return stor$port
# E0tractin$ Ip Address *(_$;trator2ip3! def *(_$;trator2ip3! stor$obj=- ip=ip.split2'!' ip=ip.split2 '!'3 3 ;=$;tration2ip-0 ;=$;tration2ip03 ;I=$;tration2ip- ;I=$;tration2ip3 ;:=$;tration2ip-I ;:=$;tration2ipI3 ;4=$;tration2ip-: ;4=$;tration2ip:3 for i in ;! for iI in ;I! for i: in ;:! for i4 in ;4! stor$obj.app$nd2 +EF.EF.EF.EF+.ormat2i1iI1i:1i433 stor$obj.app$nd2+EF.EF.EF.EF+ .ormat2i1iI1i:1i433 return stor$obj
def main23! print __author__ pars$r=optpars$.>ption(ars$r2usag$=usag$1$rsion=/$rsion3 pars$r.add_option2'i' pars$r.add_option2 'i'1 1'targ$t' 'targ$t'1typ$= 1typ$='string' 'string'1d$st= 1d$st='targ$t' 'targ$t'1h$lp= 1h$lp=+Sp$iy +Sp$iy *( Addr$ss$s Jang$ or San+1 San+ 1 d$ault=%on$3 pars$r.add_option2't' pars$r.add_option2 't'1 1+thr$ad+ +thr$ad+1typ$= 1typ$='string' 'string'1 1 d$st=+thr$ad+ d$st=+thr$ad+1 1 h$lp=+Sp$iy h$lp= +Sp$iy %umb$r o )hr$ad or Sanning + 1 d$ault='00' d$ault= '00'3 3 pars$r.add_option2'o' pars$r.add_option2 'o'1 1+output+ +output+1typ$= 1typ$='string' 'string'1 1 d$st=+output+ d$st=+output+1 1 h$lp=+Sp$iy h$lp= +Sp$iy (ath or Saing >utput in );t.+ 1 d$ault=+li$_ip.t;t+ d$ault= +li$_ip.t;t+ 3 pars$r.add_option2'' pars$r.add_option2 ''1 1'tim$out' 1typ$='string' 1typ$= 'string'1 1 d$st=+tim$out+ d$st= +tim$out+1 1 h$lp=+Sp$iy h$lp= +Sp$iy %o. > J$Ku$st ($r *(+ 1d$ault='' 1d$ault= ''3 3 2options1 args3= pars$r.pars$_args23 options.targ$t! if not if not options.targ$t! print +-7 (l$as$ (roid$ *( Jang$. $.g! LILI!I!!4M01 or Dor$1 ?h$9 J$adm$ + $;it20 $;it203 targ$t=options.targ$t thr$ad=options.thr$ad output=options.output tim$out=options.tim$out targ$t=*(_$;trator2targ$t3 (ing$r2targ$t1thr$ad1output1tim$out3 return # Tri$$er == '__main__'! ! if __nam$__ == '__main__' main23
For Usages, Raw Script And More Info: Follow my blog post link : http://www http://www.bitforestinfo.com/2017 .bitforestinfo.com/2017/02/how-to-create-ping/02/how-to-create-pingsweeping-script.html
Usages Preview
Conclusion Ping Sweeping is a very ver y sefl tec!ni"e to find live !osts# $it! $it! t!e !elp of mlti% processing modle in pyt!on, we can boost varios processes in t!e pyt!on script# And Also, &o &o 'an Follow And S!are My (log And )it!b Accont *o 'onnect 'onnec t $it! +r (itforestinfo Adience And Also $it! Me#
About Me
Bitforestinfo Bitforestinfo A A blog (ased +n tec!nical knowledge, ttorials, !ow%to gides, !acking and programming soltions# In t!is blog yo will find articles related to pyt!on programming, penetrating testing, et!ical !acking, in-, inand many more interesting topics#
My Name is Suraj Singh Bisht, A Friendly And Lazy Boy Who Want To Learn And Share Aout !"ery Thing Li#e $a%#ing, &ra%#ing, Programming, Blogging And Mu%h More' I also li#e to (rite arti%les on a (ide range o) to*i%s li#e $a%#ing, &ra%#ing, Penetration testing, Programming et%' " Python Python Is My Love, Linux Is My Habit, Web Scraping is my hobby, C/C++ is my Interest, An, !echno"ogy is my "i#e $
I live in India,
You Can Follow Me On
Email
sra.sing!bis!t/012gmail#com
Blog
www#bitforestinfo#com
RSS Feed
www#bitforestinfo#com3feeds3posts3defalt
Gitub
git!b#com3sra.sing!bis!t/01
Google!
pls#google#com33444560/0775/0//65565/ pls#google#com33444560/0775/0//65565/
Faceboo"
facebook#com3bitforestinfo3
#witter
twitter#com3bitforestinfo
Forum
www#bitforestinfo#com3p3form#!tml
Thanks For Reaing!
"ice #ay.