Useful for DHCP only networks where you can't get a reservation and have multiple machines (laptop / desktop) and you reservations are short. Requires nmap, and nmap must run as root to get the scan the subnet and get the MAC. Copy and paste this into a script file.
#!/bin/bash
# enter known values
other_mac=00:00:00:00:00:00 <-- change for the mac of the machine you want to find
subnet=1.2.3.1-254 <--change for your subnet
# don't modify from here on down
# set current date stamp
prefix=`echo $subnet | /usr/bin/cut -d "." -f1`
# find the mac of wanted pc with nmap and get current ip
# requires nmap, and nmap has to run as root, you can add your account to sudoers with visudo
# username ALL= NOPASSWD: /usr/bin/nmap
newip=`/usr/bin/sudo /usr/bin/nmap -nsP $subnet | /bin/grep -B1 -i "$other_mac" | grep $prefix | /usr/bin/cut -d " " -f2 | egrep -iv "[a-z]|[A-Z]"`
#do whatever you want here, add to your hosts file, launch command with ip, etc...
#vncviewer $newip -compresslevel 0 -quality -5
echo $newip
Showing posts with label admin scripts. Show all posts
Showing posts with label admin scripts. Show all posts
Wednesday, June 10, 2009
Friday, November 02, 2007
How to do counts on cmd scripts
@echo off
set _count=1
set _max=140
:Start
if %_count%==%_max% goto end
echo %_count%
:: increment the counter.
set /a _count=_count + 1
goto start
:end
pause
set _count=
set _max=
Wednesday, June 13, 2007
Keep alive with random PING and RANDOM wait
@echo off
set target= IP.ADD.RESS OR HOSTNAME
call:keepalive
goto:eof
:keepalive
ping -n %random:~0,1% %target% | find /i "TTL">nul
if errorlevel 0 exit
sleep %random:~0,1%
goto:keepalive
:eof
set target= IP.ADD.RESS OR HOSTNAME
call:keepalive
goto:eof
:keepalive
ping -n %random:~0,1% %target% | find /i "TTL">nul
if errorlevel 0 exit
sleep %random:~0,1%
goto:keepalive
:eof
Poor man's array in cmd/batch scripts
::create the "array"
Set VarName1=Value1
Set VarName2=Value2
Set VarName3=Value3
::parse through the "array"
For /f "tokens=2 delims==" %%i in ('set Varname') do echo %%i
Set "VarName" output is every variable that starts with "VarName" as VarName1=Value1, etc… so you only want token 2 using the equal sign as a delimeter.
Set VarName1=Value1
Set VarName2=Value2
Set VarName3=Value3
::parse through the "array"
For /f "tokens=2 delims==" %%i in ('set Varname') do echo %%i
Set "VarName" output is every variable that starts with "VarName" as VarName1=Value1, etc… so you only want token 2 using the equal sign as a delimeter.
Subscribe to:
Posts (Atom)
-
Recently I made a bonehead mistake and turned off the web gui for my DD-WRT. Luckily I was able to ssh into it, but that was rather useless ...
-
The historic firearms company has voiced its concern over the rising epidemic of school shootings plaguing the nation. "Enough thoughts...