Below is a simple python program in linux to see if a port is open or close.
#!/usr/bin/python
import socket
ip = raw_input("Enter the IP Address: ")
port = input("Enter the Port Number: ")
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if sock.connect_ex((ip,port)):
print "Port",port, "is closed"
else:
print "Port",port, "is open"
We will use which python.py to know about the location of python, so we can use it in hash bang.
next we are importing the socket library.
taking as input and port are self explanatory.
SOCKET constants and functions are used to get socket connected to sock variable.
connect_ex will throw an exception if the port is closed , and we are utilizing it to display "the port is closed"
else it will be open.
make it executable and run,...
I am not going into details, as there are many tutorials out there to learn the basics.
CYB3RTR0N
Its about cyber security, understanding concepts, learning tools,techniques and procedures, sharing code snippets and walkthroughs.
Bash program to find active ips
I am learning Ethical hacking and penetration testing these days, and thought to write something in blog so that it can be helpful for others.
So today i learned how to write a bash program to find active ips on your network.
here is the program, i will explain it below.
#!/bin/bash
if [ "$1" == "" ]
then
echo "Usage: ./ping.sh [network]"
echo "Example: ./ping.sh 192.168.1"
else
for x in {1..254} ; do
ping -c 1 $1.$x |grep "64 bytes"|cut -d" " -f4|sed 's/.$//'
done
fi
I won't go into the complete details , instead i am writing out only the problems i faced.
That is all , it worked fine for me in ubuntu. striping the text that is not important to me and only showing me the ip addresses that are active in a given network.
CYB3RTR0N
So today i learned how to write a bash program to find active ips on your network.
here is the program, i will explain it below.
#!/bin/bash
if [ "$1" == "" ]
then
echo "Usage: ./ping.sh [network]"
echo "Example: ./ping.sh 192.168.1"
else
for x in {1..254} ; do
ping -c 1 $1.$x |grep "64 bytes"|cut -d" " -f4|sed 's/.$//'
done
fi
I won't go into the complete details , instead i am writing out only the problems i faced.
- first is the if command syntax , there is a space after if [ , it will give error if you write without space
if[ - The seq command somehow didn't worked for me, (i am using ubuntu 17), so i used {1..254}, this command will let the variable take one value at a time from 1 to 254
- semi colon after the range is defined.
- must use a space after sed command i.e. sed 's/....'
That is all , it worked fine for me in ubuntu. striping the text that is not important to me and only showing me the ip addresses that are active in a given network.
CYB3RTR0N
Subscribe to:
Posts (Atom)
Regulatory Compliance and SOC 2: Which Industries and Regulatory Standards Require SOC 2?
Regulatory Compliance and SOC 2: Which Industries and Regulatory Standards Require SOC 2? SOC 2 compliance has become a critical benchmark f...
-
Below are the commands , to Decode and Encoded text from Base64 and Rot13. It is a handy and easy technique required in CTFs. Alternative...
-
WALKTHROUGH (spoiler) OF PRINTER HACKING 101 by swafox in Try Hack Me (tryhackme.com) Unit 1 introduction In This section th...