




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
HackingwithTheUltimateBeginner’soutofavailableresourcesthataremadeusingthisprogramminglanguage.throughunderstandingthebasicconceptsofprogrammingandnavigatingPythoncodes.ThisbookwillalsoserveasyourguideinunderstandingcommonhackingmethodologiesandinwillalsobeabletocreateyourownhackingscriptsusingPython,usemodulesandlibrariesthatareavailablefromthird-partysources,andlearnhowtotweakexistinghackingscriptstoaddressyourowncomputingneeds.Copyright2017bySteveTale isgearedtowardsprovidingexactandreliableinformationinregardstothetopicandissuecovered.Thepublicationissoldwiththeideathatthepublisherisnotrequiredtorenderaccounting,officiallypermitted,orotherwise,qualifiedservices.Ifadviceisnecessary,legalorprofessional,a21practicedindividualintheprofessionshouldbeordered.-FromaDeclarationofPrincipleswhichwasacceptedandapprovedequallybyaCommitteeoftheAmericanBarAssociationandaCommitteeofPublishersandAssociations.Innowayisitlegaltoreproduce,duplicate,ortransmitanypartofthis ineitherelectronicmeansorinprintedformat.Recordingofthispublicationisstrictlyprohibitedandanystorageofthis isnotallowedunlesswithwrittenpermissionfromthepublisher.All Theinformationprovidedhereinisstatedtobetruthfulandconsistent,inthatanyliability,intermsofinattentionorotherwise,byanyusageorabuseofanypolicies,processes,ordirectionscontainedwithinisthesolitaryandutterresponsibilityoftherecipientreader.Undernocircumstanceswillanylegalresponsibilityorblamebeheldagainstthepublisherforanyreparation,damages,ormonetarylossduetotheinformationherein,eitherdirectlyorindirectly.Theinformationhereinisofferedforinformationalpurposessolely,andisuniversalasso.Thepresentationoftheinformationiswithoutcontractoranytypeofguaranteeassurance.Thetrademarksthatareusedarewithoutanyconsent,andthepublicationofthetrademarkiswithoutpermissionorbackingbythetrademarkowner.Alltrademarksandbrandswithinthisbookareforclarifyingpurposesonlyandaretheownedbytheownersthemselves,notaffiliatedwiththis 歡迎加入非Python編程學(xué)習(xí)交 ,群里免費提供500+本Python書籍TableofChapter2:PythonBasicsChapter3:WritingPythonProgramsChapter6:FunctionsandModulesChapter7:SettingUpforHackingChapter8:NetworkHackingChapter9:HacksfortheWebChapter11:OtherNiftyHackstoTry歡迎加Python歡迎加Python編程學(xué)習(xí),群里免費提供500+本PythonChapter1:Preparationforexploitweaknessesinacomputer.Whilethereisnothingwrongwithusingresourcesthatarealreadymadeavailable,youwillwanttodevelopbettertoolsthatc lowyoutomakebetteruseofyourowncomputer.Becauseyouarethebestjudgewhenitcomestounderstandingyourownneeds,youareawarethatmanyoftheexistingtoolsavailableonlineorinthemarketlackThecomputingworldchangeseveryday–newhacksaredevelopedbythehourandyouc eitherperformreconnaissanceorprotectyourselffromapossibilityofanattack,thenyouarelikelytorunintosometrouble.Forexample,launchingamalwareonaedmachinethathasalreadyimproveditssecuritysystemwillnotonlycauseyourattacktofail–thelikelihoodoftheattackbeingtracedbacktoyouisalsohigh.LearningaprogramminglanguagewillalsoallowyoutoincreaseyourprobabilityofhackingsuccessanddecreasethelikelihoodofgettingdetectedbyIDS(intrusiondetectionsystems), software,ortoolsthatareusedbylawenforcement.Ifyouarelearninghowtobeawhitehathackerbylearninghowcriminalhackersactanddeveloptheirowntoolsforsystemexploitationandmanipulation,thenyouwilldefini ybeabletouseupdatedsecuritycodestocombatnewcrackingprogramsthataredevelopedeveryday.Bybeingabletocodeprogramsonthego,youwillalsobeabletodetectandpreventattacksastheyhappen.Beingabletocodeyourownhackingtoolswillalsoallowyoutocontributetothecommunityofhackersthataresharingtheirresourceswithyou–bydiscoveringabetterwaytoperformanattack,doacountermeasureagainstanillegalhack,orupdatesecurityprotocolsorabilitiesofaknowntool,youwillbeabletodoyourshareinmakingthecomputingworldamoresecureplacetobein.WhatisPythonisconsideredanopensourcelanguage,whi eansthatyoucandownloaditfromthebuthasdefini ysurvivedthetestoftime–itisstillusedtodaytocreateGUIs,webapps,games,andmoreimportantly,hackingexploitsandintrusionmitigation.Ifyouaremigratingfromanotherprogramminglanguage,youwillbeabletoeasilylearnPythonthankstoitseasyreadability.MostofthecommandsusetypicalEnglishstatementswhichwillallowyoutoimmedia yunderstandtheirpurposeevenifitisthe timethatyouhaveencounteredthislanguage.Pythoncodesarealsosomuchshorterandsimplercomparedtootherhigh-levellanguagessuchasJava,andcomeswithalibraryandfeaturesthatarealreadybuilt-in,aswellasaccesstothird-partymodulesandlibraries.Itsrobustintegratedlibrariesandthelanguagesofhackers.Here’sanexample:ifyouwanttoperformtheclassicPrintcommandtotypeout“ usingJava,youwillhavetotypeoutthefollowing:Atthispoint,yougettheideath usingPython,comparedtootherhigh-levellanguagesthataretypicallyusedforcreatingIfyouarea simplercodesandsyntax.Youwillalsobeabletorunyourcodesondifferenttypesofdevicesandoperatingsystems,suchasAndroid,Windows,Linux,andMacOSX.Ifyouareinterestedinjumrightintohacking,youwilldefini yhaveendlessfundiscoveringwhatyoucanmanipulatewithyourownprograms–Pythondoesnotonlyallowyoutoexploitandmanipulatelaptops,smartphones,anddesktops,butalsoallowyoutorunyourprogramsonmicrocontrollersthatarefoundintoys,remotecontrols,appliances,andvirtuallyanydevicethathasacomputerinIfyouareusingarecentLinuxorUNIXdistribution,youprobablyhavethePythoninstalledalready.SomeWindowsusers,particularlyHPcomputerowners,mayalsohaveitinstalledinNormally,youwouldwanttogetthelatestversion,whichis3.5.2,butyoumayalsowanttogetthelatestreleaseofPython2,whichis2.7.11,ifitismorecompatiblewiththehackingprojectsthatyouhaveinmind.WhilePython3maybethefutureofthisprogramminglanguage,certainfactorssuchascompatibilitywithyourcomputerorusingthirdpartyservicesmaymakeyoudownloadPython2instead.WindowsInstaAfteryouhavedownloadedtheinstallationpackagefromtheLinuxwebsite, runthe.exefiletoproceedwiththesetup.Youshouldbeabletogetpip, ation,andIDLEwhenyougowiththestandardinstallation.installedPythoninthecorrectpath,goto:uponinstallation.IfyouarerunningPythonforthetimeinWindows,typecmdintheRunpulledup,keyin“python”tolaunchtheprogram.MacOSXInstaYoucandownloadtheinstallerfromPython’swebsiteoryoucanuseHomebrewtogettheinstallSpacebartolaunchSpotlightsearch,andthenkeyinTerminal)andenterthiscommand:/usr/bin/ruby-e"$(curl- /Homebrew/install/master/install)"AfterHomebrewisinstalled,itwillpromptyouabouthowitwillproceedwiththeinstallation.HitEnterandthenprovideyouruserpasswordinordertoproceed.Onceinstalled,youcannowusethe“brew”commandfromtheterminaltoinstallpackagesforOSX.歡迎加入非Python編程學(xué)習(xí)交 ,群里免費提供500+本Python書籍InstalingoninstallPython.Todothat,simplykeyinthiscommand:歡迎加入 Python編程學(xué)習(xí)交 ,群里免費提供500+本Python書籍InteractingwiththePythonNowthatyouhaveinstalledPython,thenextthingthatyouneedtostolearnhowyoucanusehowentirefilesorapplicationsareinterpreted.willpullupthePythons window,orthecommandlineinWindows.InteractingUsingtheCommandTheWindowscommandline(ortheTerminalinLinuxandMacOSX)isthesimplestandstraightforwardwaytostartusingPython.Withthistool,youwillbeabletoseehowPythonoperatesbasedonhowitreactstoeverycommandthatyouenteronthe>>>prompt,whichisalsoknownastheinterpreterprompt.withthisprogramminglanguage,butthismethodwillallowyoutoeasilyexplorePython’sToexplorehowPythonoperates,takealookathowtheprintcommandcanbeusedtodisplay“Pythonisforhacking.”PullupthePythoncommandline.thefollowingline.Whatwillhappenifyoudidsomethingwrongwithyourcommand?Ifyouusedafaultysyntax,suchasan pletestatementoramisspelledcommand,youwillgetadisplayerrorthatlookslikethis:HowtoExitCtrl+Z,andthenhitEnterKeyinKeyinInteractingUsingther346P00usinganintegrateddevelopmentenvironmentorIDE.AnIDEisanapplicationthatwillprovideyouallthetoolsthatyouneedtodevelopasoftware.Usually,thesetoolsareatexteditorthatwillhelpyoutweakthesourcecodethatyouareworkingon,adebugger,andasetoftoolsforbuildautomationwhichyoucanusethroughaGUI(graphicaluserinterface).IDEswillalsoallowyoutouseintegrationwithversioncontrollibrariesthatyoucansourcefromthirdparties, eansthatyoucanpullupcodesthatarecreatedbyothersandthenmixandmatchthemwithyourowncodetogettheresultsthatyouwant.YoucangetyourpreferredIDEfromathird-partysource,suchaseducationalsitesforprogramminglanguages,orfromthedevelopersofthelanguagethemselves.P,forexample,providesyouafreeIDEthatyoucanuseasastartingpointtodevelopment,ifyouarenotsurewhichIDEwillworkbestwithyourcodingstyle.TheIDLEtoolthatcomeswithyourinstallationpackageservesasaplatformwhereyoucanitsicononyourdesktop,theStart orlocatingitontheinstallfolder.ThePythons windowwhichallowsyoutomakeuseofcolor-codedcodeinputandoutputandgeterrormessagesifyouinputawrongstatement.BrowsersandAtexteditorthatallowsyoutousemultiplewindows,colorizingforPython, pletion,undo,andotherfeaturesUsingIDLEwillallowyoutousetwowindows(theS andtheEditor)whichyoucanuse Theoptionsthatbelongtoea enuarestraightforward,whi eansthatyouwillnothaveahardtimeunderstandingwhateachofthemdoevenifyouarenewtoprogramming. File(forEditorand RecentOpen Python編程學(xué)習(xí)交 ,群里免費提供500+本Python書籍PathSaveSaveCopyEdit(forEditorand SelectFindFindFindinGotoShowShowCallFormat(EditorWindow)DedentCommenttegioPython編程學(xué)習(xí)交 ,群里免費提供500+本Python書籍TabifyUntabifyFormatRun(Editorwindow)PythonCheckRun ViewLastRestartRestart GotoStackAuto-OpenStack About Hel迎加入 Python編程學(xué)習(xí)交 ,群里免費提供500+本Python書籍PythonOtherThingsYouCanYoucanwriteyourcodesinotherIDEsortexteditorsotherthanIDLE,dependingonyourneeds.Thereisnorealguidelineinchoosingwhereyoushouldtypeoutandsaveyourcodes–aslongaswillhelpyouvisualizeyourcode,thenyouwillbeabletoachieveyourhackinggoalsandcreatethecodethatyouwanttouseinthefuture.PyCharmEducationalEditionIfyouwanttofocusonlearningPythoninsteadofconcentratingonhowyoushouldbetheeditortolearnhowcertainprogramsarewritten,orlearnusingthetutorialthatcomeswithit.Youcandownloadthisfreeeditorfro SublimeTextSublimeTextallowsyoutouseapackagemanager,whichessentiallyworksforanythatisusedtotyinwordprocessors.Italsocomeswithfeaturessuchascodefolding,whichhideslinesofcodesthatyouarenotworkingTakenotethatthisisnotafreesoftware,butitdoescomewithatrialperiodthatdoesnothaveatimelimit.Thisfreesoftwarewillallowyoutodolotsofcustomizing,whichisgreatifyouareanwith.Anotherplusfactortothissoftwareisthatithasanextendedhistoryofusage, eansthatyouhaveacommunityofusersthatyoucaneasilytapwhenyouneedsomehelp.steeplearningcurvewillpayoffin .Bylearninghowtocodethroughhackingrightaway,youwillbeabletogetagoodgraspofPythonasyouexperienceitusingdifferenttoolsthatwerealreadymadebyotherhackers.Thissoftwarecomeswithafreetrialforaweekandthenwillcost$99afterwards.n347,cPthihyouaregunningtodevelopawebappforyourhacksthenthisisprobablytheIDEthatwillworkbestforyou.Python’sbasicconcepts.歡迎加入非Python編程學(xué)習(xí)交 ,群里免費提供500+本Python書籍Chapter2:PythonYourgoal,ofcourse,istomakePythongoprintingatext.Todothat,youwillneedtolearnotherconceptsthatareessentialinaPythonscript.Youwillalsowanttocreateascriptthatiseasyforyoutounderstandandreviewinthefuture,justinanycaseyouwanttoimproveitandturnitintoaworkingtoolforyourhacks.Inordertotakeinputsandmanipulatetheminordertogetcertainresults,youwill learnhowvariablesandconstantsworkinthisprogramminglanguage.歡迎加Python編歡迎加Python編程學(xué)習(xí),群里免費提供500+本PythonThesearestatementsthatcomeafterthe#symbol.Thesepiecesoftextsallowyouto:Explaintheproblemsthatyouareaimingto eorsolveinyourprograminthecodeMakingnotesinyourcodedoesnotonlyremindyouwhatyouwanttoachieveinyourcode,butalsohelpreadersthatwillbeusingyourprogramunderstandwhatlinesofcodearesupposedto歡迎加Python編歡迎加Python編程學(xué)習(xí),群里免費提供500+本PythonLiteralLiteralconstantsarenamedassuchbecauseyoutakethesepiecesoftextfortheirliteralvalue.Theseconstantscanbe:Thesearesequencesofcharacters,whichyoucanspecifyusingsinglequote,doublequotes,ortriplequotes.Takenotethatsingleanddoublequotesfunctionsimilarlyincreatedit.HowtoFormatThereareinstancesinwhichyouwillwanttoconstructstringsfromadifferentpieceofinformation.Todothis,youwillneedtousethe method.TakealookatthisOnceyouaredone,savethispieceofcodeasstr_format.py.Thisishowit’sgoingtolooklikewhenyouruntheprogram:specification.Takealookatthisexample:歡迎加入 Python編程學(xué)習(xí)交,群里免費提供500+本Python歡迎加入 Python編程學(xué)習(xí)交,群里免費提供500+本Python歡迎加Python歡迎加Python編程學(xué)習(xí),群里免費提供500+本PythonBecausetherewillbemultipleinstancewhereinyouwillneedtostoreinformationinyourcodevariableshavevaryingvalues,suchasrealnumbers,strings,Booleans,dictionaries,orlists,whichyoucanaccessthroughcertainmethods.Takealookatthissamplecode:Inthisexample,youareabletodefinethevariablenamedport,whichisgoingtobeusedtostoretheinteger21,andthevariablenamedbanner,whichisgoingtoholdastring.Inordertocombinethesevariablestogetherasasinglestring,youwillneedtousethevariableportthroughtheuseofthestr()function.Sinceyouneedtoquicklyaccessthedatayoustored,youneedtoassignnamestovariables.Thisiswhereidentifierscometoplay.Identifiersworklikecodenamesthatyouusetopointouttosomethingthatyouhaveusedinyourcodeorprogram.Herearesomerulesthatyouneedtofollowwhenassigningthem:Theinitialcharactershouldbealetterofthealphabetoranunderscore.Theyarecase-sensitive,whi valueandnotinterchangeablewhenyouassignthemasanidentifier.ThingsthatarereferredtoasanythinginthecodethatexistsinPythonarecalledobjects.IfyouaremigratingtoPythonfromanotherprogramminglanguage,youneedtotakenotethateverythinginPython,includingstring,numbers,andfunctions,isclassifiedasanobject.Pythonallowsyoutomakeuseofalistdatastructurewhichisextremelyusefulwhenitcomestostoringcollectionsofobjects.Asaprogrammer,youcancrea data.Atthesametime,youc somakeuseofseveralbuilt-intechniquesinPythonthatwillallowyoutoinsert,index,count,sort,append,remove,pop,andevenreverseitemsinalist.Takealookatthisexample:Usingtheabovecode,youwereabletocreatealistthroughthemethodappend(),printallthespecifieditems,andthenmanagetosorttheitemsbeforeyouaskedtheprogramtoprintthemagain.Youwerealsoabletofindanitem’sindexandalsoremoveparticularitems.Python’sdictionarystructureallowsyoutomakeuseofahashtablethatcanbeusedtostoreofakeyanditscorrespondingvalue.Dictionariesareextremelyhelpfulincreatinghackingscripts.Forexample,youcancreateascannerthatisdesignedtoexploitvulnerabilitiesofaparticularsystem,suchasopenTCPports.Ifyouhaveadictionarythatwilldisplayservicenamesforcorrespondingportsthatyouwanttoexploit.Forexample,youcancreateadictionarythatwillallowyoutolookuptheftpkey,andthenprovideyouanoutputof21,whichcorrespondstoaportthatyoumaywanttotest.Youcanalsousedictionariestoperformbruteforceattackstocrackanencryptedpassword.WhatmakesPythonevenbetteristhatyoucancodeyourowndictionariesandusetheminotherscriptsthatyoumaywanttodevelopinthefuture.Whenyoucreateadictionary,keysshouldbeseparatedfromtheircorrespondingvaluewithacolon,andtheitemsshouldbeseparatedusingcommas.Inthefollowingexample,youwillbetostartusingtheminyourownscript.Inthenextchapter,youwilllearnhowareadablePythonscriptshouldlooklike.Chapter3:WritingPythonNowthatyouareawareofsomebasicconceptsthatyouneedtograspinPython,it’stimetolearnsomeguidelinesthatyouneedtorememberwhenitcomestowritingaPythonprogram.Inthischapter,youwilllearnhowtousesomeofthemostbasicconceptstorunsimplecommandsandformatyourPythoncodesinsuchawaythatitwillbeeasierforyoutounderstandandthemHowtoUseLiteralConstantsandWhathappenedinthisprogramisthatyouassignedaliteralvalueof5tothegivenvariableibecauseitindicatedthatsomethingshouldbedone,whichisconnectingthesaidvariabletoanumericalvalue.Afterwards,youprintedoutthevalueofibyusingtheprintcommand.Afterwards,youadded1tothegivenvaluethatyoustoredinthevariablei,andthenyousavedit.Whenyouusetheprintstatementagain,yougetthevalueof6.Atthesametime,youalsoassignedaliteralstringtothevariablesandthenproceededtousetheprintstatement.PhysicalandLogicalWhatyouseewhenyoutypeoutaprogramiscalledaphysicalline.WhatPythongetswhenyoueveryphysicallinethatyouseecorrespondstoagivenlogicalline.Whileyoucanusemorethanonelogicallineonaphysicallinebyusingthesemicolon(;)yourcodesmorereadable.Thisway,youwillbeabletoseelinesthatyouareworkingonandavoidpossibleconfusionwhenyouareworkingontwodifferentlogicallinesandgetlostonwhatyouaresupposedtoworkon.Pythonisoneoftheprogramminglanguagesouttherewherewhitespace,especiallythespaceatthebeginningofeachlineofcodeisimportant.Byusingindentation,youcangrouptogetherindentationwhenyouareworkingonsimilarstatements.Alsorememberthatusingthewrongindentationcanmakeyourcodepronetoerror.Takealookatthisexample: dothisforyou.Aslongasyouareconsistentwiththespacesthatyouareusing,youwillbeabletoavoidunexpectedresultsinyourcode.Chapter5:OperatorsandMostofthestatements(alsocalledlogicallines)thatyouwillbewritinginyourcodewillincludeexpressions.Expressionsaredividedintooperandsandoperators.Operatorsareessentiallyfunctionsthatdosomethinginyourcode,whicharerepresentedbyarecalledoperands.Forexample,ifyouhavetheexpression4+5,theplus(+)signistheoperator,andthenumbers4and5areoperands.歡迎加歡迎加Python編程學(xué)習(xí),群里免費提供500+本PythonTakealookathowexpressionslooklikeinaninterpreterabletoseethe resultthatyouareexpectingrightafterthelogicalline.Sinceyouwillbeproducingcodesforyourownhackingtools,youwillneedtomemorizehowoperatorsareusedinacode.AlsotakenotethatPythonusestheoperatorsaccordingtoprecedence.Thatmeansthatwhenyouaskyourcodetoperformcertainoperationsthathavehigherprecedence.Forexample,Pythonwillalwaysperformoperationsthatrequireittodi rmultiplyvariablesoveroperationsthatrequireittoaddorsubtract.Iftwooperatorshavethesamevalueofprecedence,thenPythonwillevaluatethemfromlefttoright.HereisalistoftheoperatorsthatareavailableinPlusFor4+5willgiveyou9,and‘e’+‘j’givesyou‘a(chǎn)b’Minus(-)Subtractsonenumberfromanothernumber.Incasethatthe absent,Pythonassumesthatitiszero.For-87willgiveyouanegativenumber,and80–40givesyou40.Multiply(8)Forexample:2*5givesyou10,and‘ha’*3willgiveyou‘hahaha’Power(**)Forexample:gi Py 234DivideDividesthe Forexample:4/2givesDivideandfloorDividesthe For5//2givesyou2Modulo(%)Forexample:13%3willgiveyou1Lessthan(<)Givesyouaresultofwhetherthe operatorwillsaywhetheritisTRUEorFALSE.ForGreaterthan(>)Givesyouaresultofwhetherthe willalsosaywhetheritisTRUEorFALSE.For9>3givesyouTRUEGivesyouaresultofwhetherthe operandislessthanorequaltothenextone.Forexample:x=6;y=9;x<=ygivesyouTRUEGreaterthanorequalto(>=) Forx=6;y=3;x>=ygivesyouTRUEEqualto(==)Forx=3;y=3;x==ygivesyouTRUENotequalto(!=)Forexample:x=3;y=4;x!=ygivesyouExpressionsarecombinationsofoperatorsandvaluesinyourcode.Youcanthinkofitas1),youwillgetaresultthatprovidesyouthevalueofthesetwonumbersaddedtogether.TakealookatthisAsyoumayhavenoticed,Pythonstoredvaluesinthevariables‘length’and‘breadth’,andyouareabletocalculatetheperimeterandtheareaofarectangleusingtheseexpressions.Youarealsoabletostorethevalueoftheexpressionlength*breadthinanothervariable,whichisnamedarea,andthendisplayeditusingtheprintfunction.cannowreadytolearnhowyoucanusetheminacode!Chapter6:Functionsandhavingtowriteanoperationandthenrepeatthatoverandoveragainthroughoutyourscriptinorderforyourcodetodosomething.ItisagoodthingthatPythonallowsyoutomakeuseoffunctionsandmodulesthatwillallowyoutorepeatcertainactionswithinyourcodeandinotherscriptsthatyouwillbebuildinginthefuture.Inthischapter,youwilllearnhowtocreateandmakeuseoffunctionsandmodules.Youwillalsolearnhowtoiteratecommandsthatyouhaveissuedinyourscriptinordertorepeatcertainactionsfordifferen ements,andhandleerrorsthatyoumayencounterinyourscript.InPython,afunctionallowsyoutocreateablockofcodethatwillbeabletodoanaction.Theyarealsoreusable,whi eansthatyoucanprovideanametothatstatementblockandthenrunthisblockusingthenamethatyouassigneditanywhereintheprogramthatyouarebuildingwithoutanylimit.InPythonterms,thisiscalled“callingthefunction”.wanttouse.Takealookatthisexample:ngso:Whathappenedhereisthatyouareabletodefinethefunctionsay_o,whichhasnoparameters,whichisthereasonwhythereisnovaluestatedinsidetheparentheses.Parametersareindicatedinfunctionsinordertoincludeaninputthatyoucanusetopassdifferentvaluestothefunctionandgetaspecificresultthatyouhaveinmind.Alsonoticethatyouhavemanagedtocallthefunctiontwotimesinthisexercise,whi thatyoudidnothavetowritetheentirecodeagainforPythontorepeataparticularaction.FunctionFunctionsareabletotakeinvaluesthattheywillbeabletouse,whicharecalledparameters.thefunctionandthatyouhavealreadyassignedvaluestothemonceyourunthefunction.Parametersarespecifiedwithinapairofparentheseswhenyouaredefiningthefunctionandareseparatedusingcommas.Ifyouneedtocall thefunctioninyourcode,youwillneedtosupplythevaluesinthesameway.Alsotakenotethatwhenyouaresupplyingvaluetoyourvaluesasyoucallthefunction,thesevaluesarecalledarguments.Takealookatthisexample:KeywordTherewillbeinstancesasyoucodewhereinyouhavetoomanyparametersinyourfunction–ifsomeoftheparameters. havingtoworryaboutthearguments’order,andthatyoucanassignvaluestotheparametersthatyouwanttouse,especiallywhentheotherparametersthatareavailablealreadycontainsargumentvaluesthataresetindefault.Takealookatthissamplethefollowingoutput:Thereturnstatementwillprovetobehelpful.Takealookatthisexample:followingoutput:Pythoncomeswithacoolfeaturecalleddocstrings,whichisatoolthatyoucanusethecodethatyouarecreatingandmakeiteasiertounderstand.Youc afunctionwhilethecodeisalreadyrunning.Takealookatthisexample:thefollowingoutput:whichisthe stringontheinitiallogicalline.Takenotethatdocstringsc sobeusedinclassesandmodules.Therearesomeinstanceswhereinyoumayfindittoredundanttowritethesamecodemultipletimestodoasimilarfunction,suchascheckingdifferentIPaddressesor Forthisreason,youmaywanttouseafor-loopinsteadtoiteratethesamecodefordifferentelements.Forexample,ifyouwishtoiterateacodeforthesubnetofIPaddressesfromthrough54,youcanuseafor-loopthatcontainsarangeof1to255todisplaytheentiresubnet.Takealookatthissamplecodetoseehowitisdone:Ifyouwanttoiteratethesamecodethroughalistofknownportsto yzeasystem’slookatthisexample:ExceptionEvenifyouarealreadyabletowriteaprogramwithcorrectsyntax,youmaystillgothroughlikelytoexperiencearuntimeerrorbecausePythonknowsthatitisimpossibletodoso.Whenyouattempttoperformthisaction,Pythonmightreturnwiththisoutput:exceptionhandlingwillcomeinhandy.Usingtheexampleabove,youcanusethetryorexceptstatementinordertomakeuseoftheexceptionhandlingsothatwhentheerrorhappens,theexceptionhandlingfeaturewillcatchtheerrorandthenprintthemessageonthescreen.Takealookatthisexample:Ifyouwanttoseewheretheerrorspecificallyhappenedinyourscript,youcanusethefollowingcodeinstead:another,insteadofhavingtorewritetheentirecode,thenyoucanuseofmodules.Thesimplestwaytomakemodulesistocreateafilethatcontainsallthevariablesandfunctionsthatyoumayneedtouseinafutureprogramandthensaveitasa.pyfile.Alternatively,youcanalsocreateyourmodulesinalanguageinwhichthePythoninterpreteriswritten,suchastheClanguage.Youcsohaveamoduleimportedbyanotherprogramanduseallthefunctionalitysavedinthere,whichisthesameasyouusethestandardlibrariesthatyouuseinPython.thisoutput:Whathappenedhereisthatyouimportedthesysmodule.Byusingtheimportstatement,youareabletolpythonthatyouwanttouseamodulethatcontainsthefunctionalitythatisrelatedlookforthe.sysmodule.Sincethisisabuilt-inmodule,Pythonknowsthelocationwhereitcanbefound.directoriesthatarelistedinthevariablesys.path.Onceitisfound,thestatementsfoundinthatmodulewillberun,makingitavailableforyoutouse.Thisinitializationprocessonlytakesplace timeyouimportamodule.SysPythonhasabuilt-inmodulethatprovidesyouaccesstoallobjectsthattheprogramminglinearguments, umsizeofintegersthatcanbeused,flags,pathhooks,aswellasotheravailablemodules.Beingabletointeractwiththesysmodulewillallowyoutocreatedifferentscriptsthatyoucanusefordifferenthackingpurposes.Forexample,youmaywanttoyzedifferentcommandlineargumentsduringruntime.Ifyouaregoingtobuildascannertodiscoversystemvulnerabilities,sys.argvwhichiscomprisedofallthecommandlinearguments.Takealookatthissamplecodetoseehowthismoduleisused:Whenyourunthispieceofcode,youwillseethatthecommandlineargumenthasbeenyzedandthenPythonprintsouttheresultsonthescreen.Theoutputwilllooklikethis:OSPython’sOSmoduleprovidesagreatdealofroutinesfordifferentoperatingsystems,suchasMac,Posix,andNT.Usingthismodule,youc ownwiththefile-system,permissions,userdatabase,anddifferentOSenvironment.Usingthepreviousexample,you,theuser,submittedatextfileasacommandlineargument.However,itwillalsobeofvalueifyoucancheckifthefilethatyouhavepassedexistsandthedeterminethis,youcancreateacodethatwilldisplayanerrormessageifeitheroneoftheconditionisnotmet.Youcanusethiscodetodothat:Tocheckyourcode,youcanattempttoreadafilethatisnotavailableinthesystem,whichwillcausethescriptyoujusttypedintodisplaytheerror.Afterwards,youcanenterafilenamethatwillbesuccessfullyread.Finally,youcancreatepermissionrestrictionsandseethatthescriptthatyouhavecreatedprintoutaconventionalAccessDeniedmessage:ThePythonStandardlanguage.Thisextensivecollectioncontainsseveralbuilt-inmodulesthatallowyoutoaccessdifferentfunctionalitiesinthesystem.ThePythonsstandardlibraryisalsoresponsibleforprovidingyouaccesstomodules,whicharedesignedtoenhancePython’sinherentportability.Thismeansthatyouareabletodealawaywithplatformswhenitcomestocreatingyourcodes.IfyouarerunningPythonfromaWindowsmachine,youarelikelytohavetheentirestandardlibraryincludedinyourinstallation.IfyouareoperatingusingUNIXoranysimilaroperatinggetsomeoftheoptionalcomponents.Atthispoint,youalreadyknowtheessentialsinPython.Asyoucreateyourowncodesforhackingorimportmodulesfromlibraries,youwillbeabletodiscover
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 《醫(yī)院合作醫(yī)療》課件
- 《中華茶藝與文化》課件
- 課件:人格尊嚴(yán)的法律保護(hù)與實踐教學(xué)指導(dǎo)
- 快樂的有效溝通技巧
- 薪資福利政策
- 2025年昌吉貨運從業(yè)資格考題
- 營口理工學(xué)院《生物材料表界面工程》2023-2024學(xué)年第二學(xué)期期末試卷
- 遼寧地質(zhì)工程職業(yè)學(xué)院《郵政快遞軟件設(shè)計》2023-2024學(xué)年第一學(xué)期期末試卷
- 玉溪農(nóng)業(yè)職業(yè)技術(shù)學(xué)院《生化與分子生物學(xué)實驗》2023-2024學(xué)年第二學(xué)期期末試卷
- 山西電力職業(yè)技術(shù)學(xué)院《實驗診斷F》2023-2024學(xué)年第二學(xué)期期末試卷
- 工程師評審代辦合同協(xié)議
- 小班健康活動:我會吃魚
- 專利代理師考試題庫含答案2024
- DB12 T1230-2023 政務(wù)信息資源共享 總體框架
- 管道拆除專項施工方案
- 廣西壯族自治區(qū)馬山縣實驗高中-雙休背后:從“要我學(xué)”到“我要學(xué)”的轉(zhuǎn)變-高三家長會【課件】
- GB/Z 27021.13-2025合格評定管理體系審核認(rèn)證機構(gòu)要求第13部分:合規(guī)管理體系審核與認(rèn)證能力要求
- 湖南省長沙市四大名校2024-2025學(xué)年高三2月月考語文試題(原卷版+解析版)
- 《政府采購管理研究的國內(nèi)外文獻(xiàn)綜述》5500字
- 糖尿病護(hù)理查房提出問題
- 2024年國網(wǎng)浙江省電力有限公司招聘考試真題
評論
0/150
提交評論