-
Notifications
You must be signed in to change notification settings - Fork 0
/
ifconfig.sh
116 lines (94 loc) · 3.52 KB
/
ifconfig.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/sh
# Desired location and name of the output file
output_file="/storage/emulated/0/Documents/network/network_stats.txt"
# Function to handle DNS events
handle_dns_event() {
local timestamp="$1"
local source_ip="$2"
local destination_ip="$3"
# Display the DNS event on the terminal
echo "DNS Event - Timestamp: $timestamp"
echo "Source IP: $source_ip"
echo "Destination IP: $destination_ip"
echo
# Append the DNS event to the output file
echo "DNS Event - Timestamp: $timestamp" >> "$output_file"
echo "Source IP: $source_ip" >> "$output_file"
echo "Destination IP: $destination_ip" >> "$output_file"
echo "Domain: $domain" >> "$output_file"
echo >> "$output_file"
}
# Function to get URL and IP address using ping command
get_url_and_ip() {
local ip_address="$1"
# Use nslookup to get the domain name (URL) of the IP address
domain=$(ping "$ip_address") #| awk '/name =/ {print $4}' | head -n 1)
# Display the URL and IP address on the terminal
echo "URL: $domain"
echo "IP Address: $ip_address"
echo
# Append the URL and IP address to the output file
echo "URL: $domain" >> "$output_file"
echo "IP Address: $ip_address" >> "$output_file"
echo >> "$output_file"
}
# Get the hostname
hostname=$(getprop net.hostname) #(hostname)
# If net.hostname is not set, try using ro.product.name property as a fallback
if [ -z "$hostname" ]; then
hostname=$(getprop ro.product.name)
fi
# If both properties are not set, use a default value
if [ -z "$hostname" ]; then
hostname="Unknown_Hostname"
fi
# Infinite loop
while true; do
# Get the current timestamp
timestamp=$(date +"%Y-%m-%d %H:%M:%S")
# Get the network interface names
interfaces=$(ip -br link | awk '{print $1}' | grep -v 'lo')
# Loop through each interface and display network usage statistics
for interface in $interfaces; do
# Check if the interface is rmnet_upa0 or wlan0
if [ "$interface" == "rmnet_ipa0" ] || [ "$interface" == "wlan0" ]; then
# Get network usage statistics for the interface
stats= $(ip -s -h -c -d link show dev $interface | awk '!/RX\ errors/ && !/TX\ errors/ {print}')
# Get IP addresses
ip_addresses=$(ip -d -s -c -r addr show dev $interface)
#dns_events=$( tcpdump -i $interface -n -e -vvv -s 0 -l '(((port 68 and port 67) or (port 67 and port 68)) and udp)' | awk interface= "$interface" )
#'{print timestamp, interface, $1, $2, $3, $4, $5, $6, $7, $8}')
# Display hostname, timestamp, network usage statistics, IP addresses, and DNS events on terminal
echo "Hostname: $hostname"
echo "Timestamp: $timestamp"
echo "Network Usage Statistics for $interface:"
echo "$stats"
echo
echo "IP Addresses for $interface:"
echo "$ip_addresses"
echo
echo "DNS Events:"
echo "$dns_events"
echo
# Append the output to the file
echo "Hostname: $hostname" >> "$output_file"
echo "Timestamp: $timestamp" >> "$output_file"
echo "Network Usage Statistics for $interface:" >> "$output_file"
echo "$stats" >> "$output_file"
echo >> "$output_file"
echo "IP Addresses for $interface:" >> "$output_file"
echo "$ip_addresses" >> "$output_file"
echo >> "$output_file"
# echo "DNS Events:" >> "$output_file"
# echo "$dns_events" >> "$output_file"
echo >> "$output_file"
# Process each DNS event
# while read -r line; do
# handle_dns_event $line
#done <<< "$dns_events"
fi
done
# Wait for 1 second before repeating the loop
sleep 3
# CONNEXTTION DECISIONS, SCANS
done