Python and hack

Source: Internet
Author: User

1.Python function: the keyword def () means that the function starts, you can fill in the parentheses with any variables, and then these variables are passed to the function as a reference, that is, any changes in the functions to these variables will affect their values in the main function:

2. Iterate: Iterate through multiple elements with a for loop;

>>>for x in range (1,255):

Print ("194.168.95.") +STR (x))

>>>PORTLIST=[21,22,25,80,110]

>>>for Port in Portlist:

Print (port)

3. File input/output: In the Checkvulns (banner) function to replace the new code, here is read-only mode (' R ') open the text file, using the. ReadLines () method to traverse each row in the file, must use the. Strip (' \ R ') method to remove the ENTER key for each line:

def checkvulns (Banner):

F=open ("Vuln_banners.txt", ' R ')

For line in F.readlines ():

If Line.strip (' \ n ') in banner:

Print ("[+] Server is vulnerable:" +banner.strip (' \ n '))

4.Python SYS module: The built-in SYS module gives us access to objects used or maintained by the Python interpreter, including flags, versions, maximum dimensions of integers, available modules, hook paths, standard error/input/output locations, and command-line arguments to invoke the interpreter;

The SYS.ARGV list contains all the command-line arguments:

The first sys.argv[0] element is the name of the Python script, and all subsequent command-line arguments are recorded in the remaining elements of the list;

Import Sys
If Len (SYS.ARGV) ==2:
FILENAME=SYS.ARGV[1]
Print ("[+] Reading vulnerabilities from:" +filename)


5.Python OS module: The built-in OS module provides a rich range of functions for mac,nt or POSIX operating systems; This module allows programs to interact independently with the operating system environment, file system, user database, and permissions;

Import Sys
Import OS
If Len (SYS.ARGV) ==2:
FILENAME=SYS.ARGV[1]
If not os.path.isfile (filename):
Print (' [-] ' +filename+ ' does not exist. ')
Exit (0)
If not os.access (Filename,os. R_OK):
Print (' [-] ' +filename+ ' access Denied ')
Exit (0)
Print ("[+] Reading vulnerabilities from:" +filename)


Python and hack

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.