User:Trohumet: Difference between revisions
From ICO wiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
#Autor: Toomas Rohumets A21 | #Autor: Toomas Rohumets A21 | ||
#Skript, mis loob Ubuntu serverile IP aliase | #Skript, mis loob Ubuntu serverile IP aliase | ||
#Versioon 0. | #Versioon 0.5 | ||
#Õiguste kontroll | #Õiguste kontroll | ||
if [ $UID -ne 0 ]; then | if [ $UID -ne 0 ]; then | ||
echo "Käivita skript $(basename $0) juurkasutaja õigustega" | echo "Käivita skript $(basename $0) juurkasutaja õigustega" | ||
exit 1 | exit 1 | ||
fi | fi | ||
#Kontroll kas IP on parameetrina antud | #Kontroll kas IP on parameetrina antud | ||
if [ $# -ne 1 ]; then | if [ $# -ne 1 ]; then | ||
Line 19: | Line 19: | ||
exit 1 | exit 1 | ||
fi | fi | ||
IP=$1 | |||
#Aliaste kontroll | |||
x=($(ifconfig | grep eth0: | cut -d":" -f2 | cut -d" " -f1)) | |||
if [ ! -n "$x" ]; then | |||
nr=0 | |||
else | |||
nr=${#x[@]} | |||
fi | |||
#Ping, kontrollimaks kas IP on kasutuses | #Ping, kontrollimaks kas IP on kasutuses | ||
ping -c 3 $IP | ping -c 3 $IP | ||
if [ $? -eq 0 ]; then | if [ $? -eq 0 ]; then | ||
echo "IP on olemas" | echo "IP on olemas" | ||
Line 30: | Line 39: | ||
else | else | ||
echo "IP on vaba" | echo "IP on vaba" | ||
#IP sisestus /etc/network/interfaces faili | #IP ja võrgumaski sisestus /etc/network/interfaces faili | ||
cat >> /etc/network/interfaces <<EOF | cat >> /etc/network/interfaces <<EOF | ||
auto eth0: | auto eth0:$nr | ||
iface eth0: | iface eth0:$nr inet static | ||
address $IP | address $IP | ||
netmask $(ifconfig eth0 | netmask $(ifconfig eth0 | grep Mask | cut -d ':' -f 4) | ||
EOF | EOF | ||
#Võrgule restart | #Võrgule restart | ||
/etc/init.d/networking | /etc/init.d/networking stop | ||
/etc/init.d/networking start | |||
#Tulemus | #Tulemus | ||
echo "Loodi alias IPga $IP" | echo "Loodi alias IPga $IP" | ||
fi | fi | ||
</source> | |||
==PowerShell== | |||
<source lang="powershell"> | |||
############################################################### | |||
#Autor: Toomas Rohumets A21 | |||
#Skript, mis muudab võrgukaardi MAC aadressi. | |||
#Versioon: 0.1 | |||
############################################################### | |||
$NIMI = $args[0] | |||
$MAC = $args[1] | |||
#Argumentide olemasolu kontroll | |||
IF ($args.Count -ne 2) | |||
{ | |||
echo "Käivita skript koos argumentidega nt: 'Local Area Connection' AA-BB-CC-DD-EE-FF" | |||
exit | |||
} | |||
#Võrgukaardi ID leidmine | |||
Get-WmiObject -Query "select * from win32_networkadapter where NetConnectionId='$NIMI'" | % { | |||
$ID = $_.DeviceID | |||
} | |||
#Registris katoloog määramine | |||
$pikkus = "$ID".Length | |||
IF ($pikkus -eq 1) | |||
{ | |||
$kataloog = "000" + $ID | |||
} | |||
IF ($pikkus -eq 2) | |||
{ | |||
$kataloog = "00" + $ID | |||
} | |||
IF ($pikkus -eq 3) | |||
{ | |||
$kataloog = "0" + $ID | |||
} | |||
IF ($pikkus -eq 4) | |||
{ | |||
$kataloog = $ID | |||
} | |||
#Uue MAC aadressi kirjutamine registrisse. | |||
$NetworkAddress = Remove-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\Class\"{4D36E972-E325-11CE-BFC1-08002BE10318}"\$kataloog -Name NetworkAddress -ErrorAction "SilentlyContinue" | |||
if(!$NetworkAddress) | |||
{ | |||
New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\Class\"{4D36E972-E325-11CE-BFC1-08002BE10318}"\$kataloog -Name NetworkAddress -PropertyType String -Value $MAC | |||
} | |||
#Võrgukaardi restart | |||
$NIC = Get-WmiObject -Class Win32_NetworkAdapter | Where-Object {$_.DeviceID -like "*$ID*"} | |||
$NIC.Disable() | |||
$NIC.Enable() | |||
#Teavitus | |||
echo "$NIMI'i MAC aadress muudeti $MAC" | |||
############################################################### | |||
</source> |
Latest revision as of 20:19, 21 May 2011
Quest14
#!/bin/bash
#Autor: Toomas Rohumets A21
#Skript, mis loob Ubuntu serverile IP aliase
#Versioon 0.5
#Õiguste kontroll
if [ $UID -ne 0 ]; then
echo "Käivita skript $(basename $0) juurkasutaja õigustega"
exit 1
fi
#Kontroll kas IP on parameetrina antud
if [ $# -ne 1 ]; then
echo "Käivita skript $(basename $0) koos IPga"
exit 1
fi
IP=$1
#Aliaste kontroll
x=($(ifconfig | grep eth0: | cut -d":" -f2 | cut -d" " -f1))
if [ ! -n "$x" ]; then
nr=0
else
nr=${#x[@]}
fi
#Ping, kontrollimaks kas IP on kasutuses
ping -c 3 $IP
if [ $? -eq 0 ]; then
echo "IP on olemas"
exit 1
else
echo "IP on vaba"
#IP ja võrgumaski sisestus /etc/network/interfaces faili
cat >> /etc/network/interfaces <<EOF
auto eth0:$nr
iface eth0:$nr inet static
address $IP
netmask $(ifconfig eth0 | grep Mask | cut -d ':' -f 4)
EOF
#Võrgule restart
/etc/init.d/networking stop
/etc/init.d/networking start
#Tulemus
echo "Loodi alias IPga $IP"
fi
PowerShell
###############################################################
#Autor: Toomas Rohumets A21
#Skript, mis muudab võrgukaardi MAC aadressi.
#Versioon: 0.1
###############################################################
$NIMI = $args[0]
$MAC = $args[1]
#Argumentide olemasolu kontroll
IF ($args.Count -ne 2)
{
echo "Käivita skript koos argumentidega nt: 'Local Area Connection' AA-BB-CC-DD-EE-FF"
exit
}
#Võrgukaardi ID leidmine
Get-WmiObject -Query "select * from win32_networkadapter where NetConnectionId='$NIMI'" | % {
$ID = $_.DeviceID
}
#Registris katoloog määramine
$pikkus = "$ID".Length
IF ($pikkus -eq 1)
{
$kataloog = "000" + $ID
}
IF ($pikkus -eq 2)
{
$kataloog = "00" + $ID
}
IF ($pikkus -eq 3)
{
$kataloog = "0" + $ID
}
IF ($pikkus -eq 4)
{
$kataloog = $ID
}
#Uue MAC aadressi kirjutamine registrisse.
$NetworkAddress = Remove-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\Class\"{4D36E972-E325-11CE-BFC1-08002BE10318}"\$kataloog -Name NetworkAddress -ErrorAction "SilentlyContinue"
if(!$NetworkAddress)
{
New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\Class\"{4D36E972-E325-11CE-BFC1-08002BE10318}"\$kataloog -Name NetworkAddress -PropertyType String -Value $MAC
}
#Võrgukaardi restart
$NIC = Get-WmiObject -Class Win32_NetworkAdapter | Where-Object {$_.DeviceID -like "*$ID*"}
$NIC.Disable()
$NIC.Enable()
#Teavitus
echo "$NIMI'i MAC aadress muudeti $MAC"
###############################################################