How to create a Python host checker for Linux
Hello Today we are going to create "how to create python host checker for linux" python up / down host checker working on linux.
You need:
- Python 3.4
- Internet connection
- Computer with Windows or Linux
If you have not yet installed Python, download it from the following link:
https://www.python.org/downloads/
Why Linux only?
We never recommend using a 3rd party library, but, without them, you cannot normally ping on Windows. For example, if you use the ping command on Linux, you get 1 when the host is found, and another number if it is down. This means that on Linux, when the ping target is not successfully pinged, then ping1 (operation completed successfully), in the other case, it gives you the error number. On Windows, it is more complex. If you ping with the ping command, you get the operation completed successfully, regardless of whether the host is up or down. Hower, I don't think any of you actually use Windows for hacking.
establishment
Before you begin, please connect to the Internet, and if you have another computer, that would be great. Get your local IPv4 address, think about which port you want to scan.
Coding for creating Python host checker for Linux
Coding is the easy part. Start by importing sys and sockets, then, type the following code:
import os # Importing main libs
import sys
start = "" # Setting up variables
range1 = 0
range2 = 0
for carg in sys.argv: # Checking for arguments
if carg == "-s":
argnum = sys.argv.index(carg)
argnum += 1
start = sys.argv[argnum]
elif carg == "-r1":
argnum = sys.argv.index(carg)
argnum += 1
range1r = sys.argv[argnum]
range1 = int(range1r)
elif carg == "-r2":
argnum = sys.argv.index(carg)
argnum += 1
range2r = sys.argv[argnum]
range2 = int(range2r)
print ("[*] Host Scanner launched!") # Informs user about initialize
if start == "": # Checks if all the information is provided
print ("[E] No host provided")
elif range1 == 0:
print ("[E] No range1 provided")
elif range2 == 0:
print ("[E] No range2 provided")
else:
if range1 > range2:
count = range1 - range2
elif range1 &1 >/dev/null") # Sets response to ping
if response == 0: # Reads response, checks if it is 0
err = 0 # sets err to 0
else:
err = 1 # sets err to 1
if err == 0: # when err is equal to 0
print ("[+] " + target + " is up!") # Informs user about hosts that are up
So, it is very easy. The end perimeter command in the ping command suppresses the output. So, save the file, run it from the terminal and test it!
Comments
Post a Comment