Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task 2 scripts completed #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions task-2/team-23/1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# Task 2 script 1
# Authors : SANU MUHAMMED C, SHAS, SALMAN FARIS P P, ARSHAD A T, NIHAL VADAKKAN
# Copyright (c) TEAM 23
# Scriot to scan open ports of any machine
# Script follows here

echo "For successfull execution of this script nmap should be installed"
echo "Enter hostname or Ip address"
read ip

# extracting port number only from the nmap command result
portNumber=$(nmap $ip | grep open | awk '{print $1}' | awk -F "/" '{print $1}')

while read line; do
if [ $line ]; then
echo 'port ' $line ' of the host ' $ip ' is open.'
fi
done <<< $portNumber
25 changes: 25 additions & 0 deletions task-2/team-23/2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Task 2 script 2
# Authors : SANU MUHAMMED C, SHAS, SALMAN FARIS P P, ARSHAD A T, NIHAL VADAKKAN
# Copyright (c) TEAM 23
# Scriot to monitor the network and create a monitoring log
# Script follows here

function monitor()
{
flag=$(ping -c 3 $1 > /dev/null;echo $?) #storing the exit code of ping, 0 means host reachable 2 means unreachable
if [ $flag = 0 ]; then
echo $(date +%d-%m-%y) $(date +%H:%M) ": ping success, $1 host is up!" >> network.log
else
echo $(date +%d-%m-%y) $(date +%H:%M) ": ping failed, $1 host is down!" >> network.log
fi
}

echo "Enter the IP address or host name to monitor: "
read ip

while true; do
monitor $ip
sleep 1h
done
21 changes: 21 additions & 0 deletions task-2/team-23/3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Task 2 script 3,4,5
# Authors : SANU MUHAMMED C, SHAS, SALMAN FARIS P P, ARSHAD A T, NIHAL VADAKKAN
# Copyright (c) TEAM 23
# Script follows here

url="http://gincy.pythonanywhere.com"
#endpoints: /getusers, /login, /getid

userId='{}'

request=$(curl -s $url/getusers | jq -c -r '.[][0]') #user name list

for username in $request;do
token=$( curl -s -d '{"username" : "'"${username}"'" }' -H "Content-Type: application/json" -X POST ${url}/login | jq -r)
user_id=$( curl -s -H "Authorization: $token" $url/getid | jq -r)
userId=$( echo $userId | jq ".${username}.userId |= ${user_id}")
done

echo $userId