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