How to select vendor when using macchanger in linux - linux

Currently, I am using this command to spoof my MAC address:
macchanger eth0 -A
However, I want to be able to select which vendor I use. I know that the switch -l displays a list of all available vendors, but say I want to use one from Cisco, what command do I use to actually use that specific vendor rather than the system choosing a random vendor for me each time?

You could add a function like this to .bashrc
Then you can: macspoof Apple eth0
macspoof () {
Vendor=$(macchanger -l | grep $1 | shuf -n 1 | awk '{print $3}')
Tail=$(echo $RANDOM | md5sum | sed 's/.\{2\}/&:/g' | cut -c 1-8)
Mac="$Vendor:$Tail"
sudo macchanger -m $Mac $2
}

Related

How to use ssh -t command which includes grep with quotes

I am trying to grep the third octet in IP address to an tap device on remote machine.
ssh -t user#host "/sbin/ifconfig tap0 | grep "inet" | /usr/bin/awk -F'[: ]+' '{ print $4 }' | awk -F'[.]' '{print $3}'"
I am resulting this:
inet addr:10.22.66.77 Bcast:10.22.66.255 Mask:255.255.255.0
When i run the command on the remote machine it shows 66
How to make it working with ssh -t?
Sometimes using perl is simpler:
ssh -t user#host "/sbin/ifconfig tap0" | perl -n -e 'if (/inet\saddr:\d+\.\d+\.(\d+)/) { print "$1\n"}'
it runs regular expression pattern on the local machine match on the third octet following addr: and this is then printed via $1
The pattern match is run on the local machine to avoid problems with escaping " (In your example code the " in the grep inet seems to terminate the ssh...)

Custom Splash Screen on Login RHEL

I was wondering if it was possible to display a splash screen when you log into an account in a RHEL server? not via /etc/motd as that is global but to an specific user.
Ideally I would like to show uptime and services running when a service account is logged in.
Kind regards,
R,
Check manual page for sshd_config. There is Banner option and you can customize it per-user.
Also motd can be dynamic. Check this answer on ServerFault:
However, it's possible to execute a shell script at login time that will have the same result. This is usually achieved by adapting the /etc/profile script that is executed each time a user logs in. A useful practice is to put the command you want to be executed in a script named /etc/motd.sh and call this script from /etc/profile, usually at about the end of it.
You can modify the target user's .Bash_profile and put inside of it the commands to show stuffs like cpuinfo meminfo...
Here's an example.
let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)"
let secs=$((${upSeconds}%60))
let mins=$((${upSeconds}/60%60))
let hours=$((${upSeconds}/3600%24))
let days=$((${upSeconds}/86400))
UPTIME=`printf "%d days, %02dh%02dm%02ds" "$days" "$hours" "$mins" "$secs"`
echo "`date +"%A, %e %B %Y, %r"`
`uname -srmo`
Uptime.............: ${UPTIME}
Memory.............: `cat /proc/meminfo | grep MemFree | awk {'print $2'}`kB (Free) / `cat /proc/meminfo | grep MemTotal | awk {'print $2'}`kB (Total)
Load Averages......: ${one}, ${five}, ${fifteen} (1, 5, 15 min)
Running Processes..: `ps ax | wc -l | tr -d " "`
IP Addresses.......: `/sbin/ifconfig eth0 | /bin/grep "inet addr" | /usr/bin/cut -d ":" -f 2 | /usr/bin/cut -d " " -f 1`"
this example will show you something like this:
Friday, 15 April 2016, 04:47:41 PM
Linux 2.6.18-128.el5 x86_64 GNU/Linux
Uptime.............: 2 days, 02h05m06s
Memory.............: 1805240kB (Free) / 4037732kB (Total)
Load Averages......: 0.77, 0.74, 0.89 (1, 5, 15 min)
Running Processes..: 230
IP Addresses.......: X.X.X.X
ENJOY!

get a DHCP server's IP

I wanted to get the IP of my DHCP server into a bash variable.
like : IP="192.168.1.254"
I know this IP can be found in /var/lib/dhcp/dhclient.leases or in /var/log/syslog but I don't know of to extract it and put it in variable during my script (bash)
EDIT: file dhclient.leases look's like
lease {
interface "eth0";
fixed-address 192.168.1.200;
option subnet-mask 255.255.255.0;
option routers 192.168.1.254;
option dhcp-lease-time 7200;
option dhcp-message-type 5;
option domain-name-servers 192.168.1.254;
option dhcp-server-identifier 192.168.1.254;
option host-name "bertin-Latitude-E6430s";
option domain-name "laboelec";
renew 1 2015/02/16 10:54:34;
rebind 1 2015/02/16 11:53:49;
expire 1 2015/02/16 12:08:49;
}
I want the IP from line option dhcp-server-identifier 192.168.1.254;.
To more compatibility I finally opted for a simple solution which is to send the IP server like a string on broadcast every seconds. For that I use socat (because netcat can't send message to braodcast)
my DHCP server run this script in background:
#!/bin/bash
interface="eth0"
IP=$(ifconfig $interface | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}')
Broadcast=$(ifconfig $interface | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f3 | awk '{ print $1}')
Port="5001"
while [ true ];
do
sleep 1
echo $IP | socat - UDP4-DATAGRAM:$Broadcast:$Port,so-broadcast
#to listen: netcat -l -u $Broadcast -p $Port
done
exit 0

Command line shell for identifying interfaces that are up and running

Is there any shell command for filtering interface names that are up and running
Run the command /sbin/ifconfig and look for UP.
If you want just the names of the active interfaces, you need some scripting:
ifconfig | awk '/^[^ ]/ { name=$1; } /^ +UP / {print name;}'
You may check it with several commands:
See the content of the network interface file:
cat /sys/class/net/eth0/operstate
Using ip command
ip a | grep -Eq ': eth0:.*state UP'
Or:
ifconfig | grep -Eq ': eth0:.*state UP'
Where eth0 is your interface. Original post
ifconfig | awk -v RS="" '/MULTICAST/ && /UP/ && /RUNNING/ && /BROADCAST/ {print substr($1, 0, length($1)-1)}'

How to cut ifconfig to get eth* details alone?

I'm writing a script to print ethtool details of ifconfig.
Sample output should be from ifconfig is like,
eth0
eth1
eth2
I have tried using below command,
root#bt# ifconfig | cut -d ":" -f 1
But could not able to achieve the same.
Actually, i need to get these eth* and pass in
root#bt# ethtool <arg1> where arg1=eth*
to get results :-) can you please help me to get crop from ifconfig. ?
No.
$ awk -F: '$1 ~ "eth" { print $1 }' /proc/net/dev
eth0
With grep & ifconfig :
ifconfig | grep -o '^eth[0-9]\+'
Or with only grep :
grep -oP '^ *\Keth[0-9]+' /proc/net/dev

Resources