воскресенье, 28 июня 2009 г.

Скрипт, подключение принтера в зависимости от настроек сетевого адаптера

"Dim dbg: dbg = True
Dim networkIDs: Set networkIDs = CreateObject("Scipting.Dictionary")
Dim Nacs, Nac
Set Nacs = GetObject("winmgmts://./root/cimv2").ExecQuery(_ "Select IPAddress,IPSubnet from Win32_NetworkAdapterConfiguration" _ & "where IPEnabled = true")
For each Nac in Nacs
Dim N
If ( Not IsNull(Nac.IPAddress)) And (Not IsNull(Nac.IPSubnet)) Then
For N = 0 To UBound(Nac.IPAddress)
networkIDs(NetworkID(Nac.IPAddress(N),Nac.IPSubnet(N))) = vbNullString
Next
End If
Next
Dim IDList: IDList = networkIDs.keys

Dim Locations: Set Locations = CreateObject("Scripting.Dictionary")
Locations("HQ") = "192.168.254.0"
Locations("Br_Moscow") = "192.168.177.0"

Dim SystemLocation
SystemLocation = vbNullString
Dim MultipleMatches
MultipleMatches = False

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
Dim Session
Session = WshShell.ExpandEnvironmentStrings("%SessionName%")
If Session = "Console" or Session = "%SessionName%" Then
Dim Location
For Each Location in Locations.Keys
Dim curentID
For Each currentID in IDList
"If dbg Then WScript.Echo "ID:", "CurrentID
If currentID = Locations(Location) Then
If dbg Then WScript.Echo "matched", CurrentID
If SystemLocation <> vbNullString Then
MultiplleMatches = True
Else
SystemLocation = Location
End If
End If
Next
Next
End IF

If Not MultipleMatches Then
Dim WshNetwork
Set WshNetwork = CreateObject("WScript.Network")

Select Case SystemLocation
Case "HQ"
`Code to map HQ printers. Example:
`WshNetwork.AddPrinterConnection "Default","\\SRVPRIN\printer"
Case "BR_Moscow"
Case Else
"If dbg then
"Wscript.Echo "No matching location found."
"WScript.Echo "SystemLocation:", SystemLocation
"End If
End Select
End If

Function NetworkID(Address,Mask)
Dim AddressOctets, MaskOctets, Result, N
AddressOctets = Split(Address, ".")
MaskOctets = Split(Mask, ".")
ReDim Result(UBound(AddressOctets))
For N = 0 To UBound(AddressOctets)
Result(N) = AddressOctets(N) And MaskOctets(N)
Next
NetworkID = Join(Result,".")
End Function

среда, 3 июня 2009 г.

Настройка TFTP в Fedora 9

Для установки у настройки TFTP сервера необходимы права суперпользователя (root).

1. Установка пакета
yum install tftp-server

2. Настройка конфигурации
vi /etc/xinetd.d/tftp
строку:
disable = yes
исправляем на:
disable = no

3) Добавляем tftp в список служб, автоматически стартуемых при загрузке Linux:
/sbin/chkconfig tftp on
/sbin/chkconfig xinetd on
/sbin/service xinetd start

по умолчанию корневой папкой для TFTP является /var/lib/tftpboot

для нее делаем:
chown nobody:nobody -R /var/lib/tftpboot

Проверка (требует установленного пакета tftp)
$ tftp 192.168.54.2
tftp> status
tftp> get 1.txt
Received 769 bytes in 5.1 seconds
tftp> quit

P.s.: Справку по командам можно получить с помощью ввода "?"