How do I add this field? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election Results Why I closed the “Why is Kali so hard” questionWhy does this incrementing for loop return a bad variable?Update mysql database specific field with this bash scriptMAC address through ad hoc wifiWhy this expression does not expand in Bash for-for structure?How to add an IE field for my wifi hotspot?How can I add this directory to my bash profile?QEMU Deb9 guest graphical install fails to get DHCP reply during installWhy does this for loop ignore my variable?How do I add a variable to this curl command?Frequent channel switching - any client-only diagnostics?
Is CEO the profession with the most psychopaths?
What causes the direction of lightning flashes?
Dating a Former Employee
How do pianists reach extremely loud dynamics?
How to Make a Beautiful Stacked 3D Plot
How to answer "Have you ever been terminated?"
Delete nth line from bottom
When the Haste spell ends on a creature, do attackers have advantage against that creature?
Should I use a zero-interest credit card for a large one-time purchase?
How do I find out the mythology and history of my Fortress?
Around usage results
What's the meaning of "fortified infraction restraint"?
How to find all the available tools in mac terminal?
How do I make this wiring inside cabinet safer? (Pic)
What does "lightly crushed" mean for cardamon pods?
Why are both D and D# fitting into my E minor key?
Can you use the Shield Master feat to shove someone before you make an attack by using a Readied action?
Do I really need to have a message in a novel to appeal to readers?
When a candle burns, why does the top of wick glow if bottom of flame is hottest?
Wu formula for manifolds with boundary
What font is "z" in "z-score"?
What is the meaning of the simile “quick as silk”?
Generate an RGB colour grid
Why are the trig functions versine, haversine, exsecant, etc, rarely used in modern mathematics?
How do I add this field?
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionWhy does this incrementing for loop return a bad variable?Update mysql database specific field with this bash scriptMAC address through ad hoc wifiWhy this expression does not expand in Bash for-for structure?How to add an IE field for my wifi hotspot?How can I add this directory to my bash profile?QEMU Deb9 guest graphical install fails to get DHCP reply during installWhy does this for loop ignore my variable?How do I add a variable to this curl command?Frequent channel switching - any client-only diagnostics?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to print the signal strength of two wifi devices connected to a hotspot. I manage to do this script that prints the ip, hostname, mac and signal. In the script below the macs are stored in $maclist
, same with signals in $signallist
, the problem is that when I try to do the loop it only prints the first signal stored but not the second.
#!/bin/bash
# show_wifi_clients.sh
# Shows MAC, IP address and any hostname info for all connected wifi devices
echo "# All connected wifi devices, with IP address,"
echo "# hostname (if available), and MAC address."
printf "# %-20s %-30s %-20s %-20sn" "IP address" "Lease name" "MAC address" "Signal"
leasefile=/var/lib/misc/dnsmasq.leases
# list all wireless network interfaces
# Gets "wlan0" for the variable interface
for interface in `iw dev | grep Interface | cut -f 2 -s -d" "`
do
# for each interface, get mac addresses of connected stations/clients
maclist=`iw dev $interface station dump | grep Station | cut -f 2 -s -d" "`
# for each interface, get their signals
signallist=`iw dev $interface station dump | grep signal: | awk 'print $2'`
# for each mac address in that list...
for mac in $maclist
do
# If a DHCP lease has been given out by dnsmasq,
# save it.
for signal in $signallist
do
ip="UNKN"
host=""
ip=`cat $leasefile | cut -f 2,3,4 -s -d" " | grep $mac | cut -f 2 -s -d" "`
host=`cat $leasefile | cut -f 2,3,4 -s -d" " | grep $mac | cut -f 3 -s -d" "`
# ... show the mac address:
done
printf " %-20s %-30s %-20s %-20sn" $ip $host $mac $signal
done
done
Output
# All connected wifi devices, with IP address,
# hostname (if available), and MAC address.
# IP address Lease name MAC address Signal
10.42... device1 b8:27:eb:... -45
10.42... device2 b4:9d:0b:... -45
bash ubuntu wifi macintosh for
New contributor
add a comment |
I'm trying to print the signal strength of two wifi devices connected to a hotspot. I manage to do this script that prints the ip, hostname, mac and signal. In the script below the macs are stored in $maclist
, same with signals in $signallist
, the problem is that when I try to do the loop it only prints the first signal stored but not the second.
#!/bin/bash
# show_wifi_clients.sh
# Shows MAC, IP address and any hostname info for all connected wifi devices
echo "# All connected wifi devices, with IP address,"
echo "# hostname (if available), and MAC address."
printf "# %-20s %-30s %-20s %-20sn" "IP address" "Lease name" "MAC address" "Signal"
leasefile=/var/lib/misc/dnsmasq.leases
# list all wireless network interfaces
# Gets "wlan0" for the variable interface
for interface in `iw dev | grep Interface | cut -f 2 -s -d" "`
do
# for each interface, get mac addresses of connected stations/clients
maclist=`iw dev $interface station dump | grep Station | cut -f 2 -s -d" "`
# for each interface, get their signals
signallist=`iw dev $interface station dump | grep signal: | awk 'print $2'`
# for each mac address in that list...
for mac in $maclist
do
# If a DHCP lease has been given out by dnsmasq,
# save it.
for signal in $signallist
do
ip="UNKN"
host=""
ip=`cat $leasefile | cut -f 2,3,4 -s -d" " | grep $mac | cut -f 2 -s -d" "`
host=`cat $leasefile | cut -f 2,3,4 -s -d" " | grep $mac | cut -f 3 -s -d" "`
# ... show the mac address:
done
printf " %-20s %-30s %-20s %-20sn" $ip $host $mac $signal
done
done
Output
# All connected wifi devices, with IP address,
# hostname (if available), and MAC address.
# IP address Lease name MAC address Signal
10.42... device1 b8:27:eb:... -45
10.42... device2 b4:9d:0b:... -45
bash ubuntu wifi macintosh for
New contributor
What is the output of justiw dev "$interface" station dump
?
– Jesse_b
3 hours ago
add a comment |
I'm trying to print the signal strength of two wifi devices connected to a hotspot. I manage to do this script that prints the ip, hostname, mac and signal. In the script below the macs are stored in $maclist
, same with signals in $signallist
, the problem is that when I try to do the loop it only prints the first signal stored but not the second.
#!/bin/bash
# show_wifi_clients.sh
# Shows MAC, IP address and any hostname info for all connected wifi devices
echo "# All connected wifi devices, with IP address,"
echo "# hostname (if available), and MAC address."
printf "# %-20s %-30s %-20s %-20sn" "IP address" "Lease name" "MAC address" "Signal"
leasefile=/var/lib/misc/dnsmasq.leases
# list all wireless network interfaces
# Gets "wlan0" for the variable interface
for interface in `iw dev | grep Interface | cut -f 2 -s -d" "`
do
# for each interface, get mac addresses of connected stations/clients
maclist=`iw dev $interface station dump | grep Station | cut -f 2 -s -d" "`
# for each interface, get their signals
signallist=`iw dev $interface station dump | grep signal: | awk 'print $2'`
# for each mac address in that list...
for mac in $maclist
do
# If a DHCP lease has been given out by dnsmasq,
# save it.
for signal in $signallist
do
ip="UNKN"
host=""
ip=`cat $leasefile | cut -f 2,3,4 -s -d" " | grep $mac | cut -f 2 -s -d" "`
host=`cat $leasefile | cut -f 2,3,4 -s -d" " | grep $mac | cut -f 3 -s -d" "`
# ... show the mac address:
done
printf " %-20s %-30s %-20s %-20sn" $ip $host $mac $signal
done
done
Output
# All connected wifi devices, with IP address,
# hostname (if available), and MAC address.
# IP address Lease name MAC address Signal
10.42... device1 b8:27:eb:... -45
10.42... device2 b4:9d:0b:... -45
bash ubuntu wifi macintosh for
New contributor
I'm trying to print the signal strength of two wifi devices connected to a hotspot. I manage to do this script that prints the ip, hostname, mac and signal. In the script below the macs are stored in $maclist
, same with signals in $signallist
, the problem is that when I try to do the loop it only prints the first signal stored but not the second.
#!/bin/bash
# show_wifi_clients.sh
# Shows MAC, IP address and any hostname info for all connected wifi devices
echo "# All connected wifi devices, with IP address,"
echo "# hostname (if available), and MAC address."
printf "# %-20s %-30s %-20s %-20sn" "IP address" "Lease name" "MAC address" "Signal"
leasefile=/var/lib/misc/dnsmasq.leases
# list all wireless network interfaces
# Gets "wlan0" for the variable interface
for interface in `iw dev | grep Interface | cut -f 2 -s -d" "`
do
# for each interface, get mac addresses of connected stations/clients
maclist=`iw dev $interface station dump | grep Station | cut -f 2 -s -d" "`
# for each interface, get their signals
signallist=`iw dev $interface station dump | grep signal: | awk 'print $2'`
# for each mac address in that list...
for mac in $maclist
do
# If a DHCP lease has been given out by dnsmasq,
# save it.
for signal in $signallist
do
ip="UNKN"
host=""
ip=`cat $leasefile | cut -f 2,3,4 -s -d" " | grep $mac | cut -f 2 -s -d" "`
host=`cat $leasefile | cut -f 2,3,4 -s -d" " | grep $mac | cut -f 3 -s -d" "`
# ... show the mac address:
done
printf " %-20s %-30s %-20s %-20sn" $ip $host $mac $signal
done
done
Output
# All connected wifi devices, with IP address,
# hostname (if available), and MAC address.
# IP address Lease name MAC address Signal
10.42... device1 b8:27:eb:... -45
10.42... device2 b4:9d:0b:... -45
bash ubuntu wifi macintosh for
bash ubuntu wifi macintosh for
New contributor
New contributor
edited 8 hours ago
Jesse_b
14.4k33574
14.4k33574
New contributor
asked 9 hours ago
Alvaromr7Alvaromr7
61
61
New contributor
New contributor
What is the output of justiw dev "$interface" station dump
?
– Jesse_b
3 hours ago
add a comment |
What is the output of justiw dev "$interface" station dump
?
– Jesse_b
3 hours ago
What is the output of just
iw dev "$interface" station dump
?– Jesse_b
3 hours ago
What is the output of just
iw dev "$interface" station dump
?– Jesse_b
3 hours ago
add a comment |
1 Answer
1
active
oldest
votes
Since you are using bash you might as well take advantage of arrays instead of looping over unquotted variables. I'm not sure what input you are providing from signallist though, but your printf
command is outside that loop. That means it may be looping through multiple signals but will only provide output once per mac address. Try moving it into the signallist loop
#!/bin/bash
echo "# All connected wifi devices, with IP address,"
echo "# hostname (if available), and MAC address."
printf "# %-20s %-30s %-20s %-20sn" "IP address" "Lease name" "MAC address" "Signal"
leasefile=/var/lib/misc/dnsmasq.leases
for interface in $(iw dev | grep Interface | cut -f 2 -s -d" "); do
maclist=( $(iw dev "$interface" station dump | grep Station | cut -f 2 -s -d" ") )
signallist=( $(iw dev "$interface" station dump | awk '/signal:/print $2') )
for mac in "$maclist[@]"; do
for signal in "$signallist[@]"; do
ip="UNKN"
host=""
ip=$(cut -f 2,3,4 -s -d" " "$leasefile" | grep $mac | cut -f 2 -s -d" ")
host=$(cut -f 2,3,4 -s -d" " "$leasefile" | grep $mac | cut -f 3 -s -d" ")
printf " %-20s %-30s %-20s %-20sn" "$ip" "$host" "$mac" "$signal"
done
done
done
Additionally I have quoted your variables, removed the UUOCs, and changed all backticks to $()
.
I tried what you told me but it doesn't work either. Using the solution you gave me I got the same output repeated twice and the signallist contains two numbers say, -35 and 60.
– Alvaromr7
4 hours ago
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Alvaromr7 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f513058%2fhow-do-i-add-this-field%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Since you are using bash you might as well take advantage of arrays instead of looping over unquotted variables. I'm not sure what input you are providing from signallist though, but your printf
command is outside that loop. That means it may be looping through multiple signals but will only provide output once per mac address. Try moving it into the signallist loop
#!/bin/bash
echo "# All connected wifi devices, with IP address,"
echo "# hostname (if available), and MAC address."
printf "# %-20s %-30s %-20s %-20sn" "IP address" "Lease name" "MAC address" "Signal"
leasefile=/var/lib/misc/dnsmasq.leases
for interface in $(iw dev | grep Interface | cut -f 2 -s -d" "); do
maclist=( $(iw dev "$interface" station dump | grep Station | cut -f 2 -s -d" ") )
signallist=( $(iw dev "$interface" station dump | awk '/signal:/print $2') )
for mac in "$maclist[@]"; do
for signal in "$signallist[@]"; do
ip="UNKN"
host=""
ip=$(cut -f 2,3,4 -s -d" " "$leasefile" | grep $mac | cut -f 2 -s -d" ")
host=$(cut -f 2,3,4 -s -d" " "$leasefile" | grep $mac | cut -f 3 -s -d" ")
printf " %-20s %-30s %-20s %-20sn" "$ip" "$host" "$mac" "$signal"
done
done
done
Additionally I have quoted your variables, removed the UUOCs, and changed all backticks to $()
.
I tried what you told me but it doesn't work either. Using the solution you gave me I got the same output repeated twice and the signallist contains two numbers say, -35 and 60.
– Alvaromr7
4 hours ago
add a comment |
Since you are using bash you might as well take advantage of arrays instead of looping over unquotted variables. I'm not sure what input you are providing from signallist though, but your printf
command is outside that loop. That means it may be looping through multiple signals but will only provide output once per mac address. Try moving it into the signallist loop
#!/bin/bash
echo "# All connected wifi devices, with IP address,"
echo "# hostname (if available), and MAC address."
printf "# %-20s %-30s %-20s %-20sn" "IP address" "Lease name" "MAC address" "Signal"
leasefile=/var/lib/misc/dnsmasq.leases
for interface in $(iw dev | grep Interface | cut -f 2 -s -d" "); do
maclist=( $(iw dev "$interface" station dump | grep Station | cut -f 2 -s -d" ") )
signallist=( $(iw dev "$interface" station dump | awk '/signal:/print $2') )
for mac in "$maclist[@]"; do
for signal in "$signallist[@]"; do
ip="UNKN"
host=""
ip=$(cut -f 2,3,4 -s -d" " "$leasefile" | grep $mac | cut -f 2 -s -d" ")
host=$(cut -f 2,3,4 -s -d" " "$leasefile" | grep $mac | cut -f 3 -s -d" ")
printf " %-20s %-30s %-20s %-20sn" "$ip" "$host" "$mac" "$signal"
done
done
done
Additionally I have quoted your variables, removed the UUOCs, and changed all backticks to $()
.
I tried what you told me but it doesn't work either. Using the solution you gave me I got the same output repeated twice and the signallist contains two numbers say, -35 and 60.
– Alvaromr7
4 hours ago
add a comment |
Since you are using bash you might as well take advantage of arrays instead of looping over unquotted variables. I'm not sure what input you are providing from signallist though, but your printf
command is outside that loop. That means it may be looping through multiple signals but will only provide output once per mac address. Try moving it into the signallist loop
#!/bin/bash
echo "# All connected wifi devices, with IP address,"
echo "# hostname (if available), and MAC address."
printf "# %-20s %-30s %-20s %-20sn" "IP address" "Lease name" "MAC address" "Signal"
leasefile=/var/lib/misc/dnsmasq.leases
for interface in $(iw dev | grep Interface | cut -f 2 -s -d" "); do
maclist=( $(iw dev "$interface" station dump | grep Station | cut -f 2 -s -d" ") )
signallist=( $(iw dev "$interface" station dump | awk '/signal:/print $2') )
for mac in "$maclist[@]"; do
for signal in "$signallist[@]"; do
ip="UNKN"
host=""
ip=$(cut -f 2,3,4 -s -d" " "$leasefile" | grep $mac | cut -f 2 -s -d" ")
host=$(cut -f 2,3,4 -s -d" " "$leasefile" | grep $mac | cut -f 3 -s -d" ")
printf " %-20s %-30s %-20s %-20sn" "$ip" "$host" "$mac" "$signal"
done
done
done
Additionally I have quoted your variables, removed the UUOCs, and changed all backticks to $()
.
Since you are using bash you might as well take advantage of arrays instead of looping over unquotted variables. I'm not sure what input you are providing from signallist though, but your printf
command is outside that loop. That means it may be looping through multiple signals but will only provide output once per mac address. Try moving it into the signallist loop
#!/bin/bash
echo "# All connected wifi devices, with IP address,"
echo "# hostname (if available), and MAC address."
printf "# %-20s %-30s %-20s %-20sn" "IP address" "Lease name" "MAC address" "Signal"
leasefile=/var/lib/misc/dnsmasq.leases
for interface in $(iw dev | grep Interface | cut -f 2 -s -d" "); do
maclist=( $(iw dev "$interface" station dump | grep Station | cut -f 2 -s -d" ") )
signallist=( $(iw dev "$interface" station dump | awk '/signal:/print $2') )
for mac in "$maclist[@]"; do
for signal in "$signallist[@]"; do
ip="UNKN"
host=""
ip=$(cut -f 2,3,4 -s -d" " "$leasefile" | grep $mac | cut -f 2 -s -d" ")
host=$(cut -f 2,3,4 -s -d" " "$leasefile" | grep $mac | cut -f 3 -s -d" ")
printf " %-20s %-30s %-20s %-20sn" "$ip" "$host" "$mac" "$signal"
done
done
done
Additionally I have quoted your variables, removed the UUOCs, and changed all backticks to $()
.
answered 8 hours ago
Jesse_bJesse_b
14.4k33574
14.4k33574
I tried what you told me but it doesn't work either. Using the solution you gave me I got the same output repeated twice and the signallist contains two numbers say, -35 and 60.
– Alvaromr7
4 hours ago
add a comment |
I tried what you told me but it doesn't work either. Using the solution you gave me I got the same output repeated twice and the signallist contains two numbers say, -35 and 60.
– Alvaromr7
4 hours ago
I tried what you told me but it doesn't work either. Using the solution you gave me I got the same output repeated twice and the signallist contains two numbers say, -35 and 60.
– Alvaromr7
4 hours ago
I tried what you told me but it doesn't work either. Using the solution you gave me I got the same output repeated twice and the signallist contains two numbers say, -35 and 60.
– Alvaromr7
4 hours ago
add a comment |
Alvaromr7 is a new contributor. Be nice, and check out our Code of Conduct.
Alvaromr7 is a new contributor. Be nice, and check out our Code of Conduct.
Alvaromr7 is a new contributor. Be nice, and check out our Code of Conduct.
Alvaromr7 is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f513058%2fhow-do-i-add-this-field%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
-bash, for, macintosh, ubuntu, wifi
What is the output of just
iw dev "$interface" station dump
?– Jesse_b
3 hours ago