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

Team 7 | Task 2 Submission #37

Open
wants to merge 5 commits 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
24 changes: 24 additions & 0 deletions task-2/team-7/script1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

read -p "Enter an IP Address: " inputIP

res=$(nmap -sT -Pn $inputIP)
i=0

while ((i++));read line; do

if [ "$i" -eq 2 ];then
ip="$( echo $line | awk -F "(" '{print $2}' | awk -F ")" '{print $1}' )"
fi

if [[ "$line" = */* && "$line" != *//* ]]; then

status="$(echo $line | awk '{print $2}')"

if [ "$status" = "open" ];then
printf "port $(echo $line | awk -F "/" '{print $1}') of $ip is open.\n"
fi

fi

done <<< "$res"
18 changes: 18 additions & 0 deletions task-2/team-7/script2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

function check_ping(){
now=$(date +'%m/%d/%Y')
status=$(ping -c 10 $1 > /dev/null;echo $?)
# echo $status
if [ $status = 0 ];then
echo "$now : ping success, $1 host is up!" >> monitor.log
else
echo "$now : ping failed, $1 host is down!" >> monitor.log
fi
}

read -p "Enter an IP Address: " inputIP
while true; do
check_ping $inputIP
sleep 1h
done
11 changes: 11 additions & 0 deletions task-2/team-7/script3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

data=$(curl -s 'http://gincy.pythonanywhere.com/getusers' | jq -c '.[]')
result='{}'
for user in ${data[@]};do
username=$( echo "${user[0]}" | jq -r '.[0]' )
token=$( curl -s -d '{"username" : "'"${username}"'" }' -H "Content-Type: application/json" -X POST 'http://gincy.pythonanywhere.com/login' | jq -r)
user_id=$( curl -s -H "Authorization: $token" 'http://gincy.pythonanywhere.com/getid' | jq -r)
result=$( echo $result | jq ".${username} |= ${user_id}")
done
echo $result