elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Únete al Grupo Steam elhacker.NET


  Mostrar Mensajes
Páginas: [1] 2 3
1  Programación / Scripting / Re: Resolucion de IP y DNS - Powershell en: 4 Abril 2013, 16:51 pm
Solucion :

Si alguien esta interesado

Código:

$computers= Get-Content C:\sql.txt
$list = @()

Foreach ($computername in $computers)
{
 If(Test-Connection $computername -Quiet)
 {

 write-host "$computername - $IP - OK" -ForegroundColor GREEN
 Try
 {
$IP = [System.Net.Dns]::GetHostEntry($computername).AddressList | %{$_.IPAddressToString}
 $IP | %{$HostName = [System.Net.Dns]::GetHostEntry($_).HostName}
 }

 Catch
 {
 write-error "NO se puede resolver el IP o DNS."
 }


 $compStatus = New-Object PSObject -Property @{           
        Equipo  = $computername
    Status = $true               
        DNS = $HostName   
    IP = $IP             
}
 $list += $compStatus

}

 Else
 {
 write-host "$computername - $IP - NO_OK" -ForegroundColor RED
 $IP = $null
 $HostName = $null
 $compStatus = New-Object PSObject -Property @{           
        Equipo  = $computername
    Status = $false
        DNS = $null
     IP = $null
 }
 $list += $compStatus

}
}
$list | Export-Csv c:\prueba2.csv -NoTypeInformation

2  Programación / Scripting / Resolucion de IP DNS VBSCRIPT en: 4 Abril 2013, 16:48 pm
Buenas tardes,

Tengo un problema, bueno uno de muchos. Ahora el problema va por VBSCRIPT planteo el requerimiento.

Tengo que realizar informacion de un una relacion de maquinas las cuales tengo que hacr ping y tengo que resolver el IP y que resuelve el DNS.

Hostname        IP       PING            DNS
MyPc          127.0.0.1  OK          MyPC.Dominio.com
Mypc2        127.0.0.2   NO_OK   No register host

Esta  informacion pasarlo a un CSV.

Pero tambien necesito trabajar con los equipos por separado es decir que me saque un log por separado de los equipos que hacen ping y los que no. esto esta en un TXT.

si alguien me puede ayudar se lo agradecería adjunto el codigo.

Código:

Dim strComputerName, ScriptPath, OnlineFileName, OfflineFileName
Dim ArgObj, OnlineFile, OfflineFile, oInputFile, InputFileName
Dim ReadLineArray(3000), a, b, c, Temp

Const ForAppending = 8
Const ForReading = 1
Const ForWriting = 2
Const ReadTheFile = False
Const CreateTheFile = True

' Valores de Formato
Const ASCII = 0
Const UniCode = -1
Const Default = -2

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = WScript.CreateObject("WScript.Shell")

' ********************   Declaracion de Varibles  ********************

' Declaracion de nombre de archivos
'*********************************************************************
FilePath=CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")


Set ArgObj = WScript.Arguments
If WScript.Arguments.count > 0 Then
  InputFileName = UCase(ArgObj(0))
Else
  InputFileName = FilePath & "\IP_List.txt"
End If

OnlineFileName = FilePath & "\OnlineSystems.txt"
OfflineFileName = FilePath & "\OfflineSystems.txt"


' Elimina los arhivos TXT Online y Offline si es que existe
'*********************************************************************
If oFSO.FileExists(OfflineFileName) = True Then
  oFSO.deletefile OfflineFileName, force
End If
If oFSO.FileExists (OnlineFileName)  Then
  oFSO.deletefile OnlineFileName, force
End If

' Crea los Archivos Online y Offline
'*********************************************************************
oFSO.CreateTextFile OnlineFileName, CreateTheFile
oFSO.CreateTextFile OfflineFileName, CreateTheFile

' Abre el archivo y lee el contenido
'*********************************************************************
Set OnlineFile=oFSO.OpenTextFile(OnlineFileName, ForWriting, ReadTheFile)
Set OfflineFile=oFSO.OpenTextFile(OfflineFileName, ForWriting, ReadTheFile)
Set oInputFile=oFSO.OpenTextFile(InputFileName, ForReading, ReadTheFile)

' Loop through the InputFile to get all the computer names and then check to see if they are online or not.

' Importa la informacion del archivo en el array
'*********************************************************************
Do while not oInputFile.AtEndOfStream
  a = a + 1
  ReadLineArray(a) = Trim(oInputFile.ReadLine) ' Reads the line of text
Loop

' Busca duplicaciones
'*********************************************************************
For b = 1 To a
  ' If data matches, then set the duplicates in the array to "" (blank)
  For c = (b + 1) To a
    If trim(ReadlineArray(b)) <> "" And trim(ReadLineArray(b)) = trim(ReadLineArray(c)) Then
      ' Found a duplicate!  Set it to blank
      ReadLineArray(c) = ""
    End If
  Next
Next

' Copy information into "output.txt" text file (exclude blank lines).
'*********************************************************************
For b = 1 To a
  If trim(ReadlineArray(b)) <> "" Then
    strComputerName = trim(ReadlineArray(b))
    IsConnectible
  End If
Next

' Cierra todos los archivos abiertos
'*********************************************************************
OnlineFile.close
OfflineFile.close

' Let user know the program has completed its operation.
wscript.echo "Finished"
'*********************************************************************

Function IsConnectible

  Dim objPing,objStatus
   
  ' Test to see if the remote machine is online or offline
'*********************************************************************
  Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
  ExecQuery("select Replysize from Win32_PingStatus where address = '" & strComputerName & "'")
   
  ' Test for the status.  If the system is Null or if its offline or does not exist on the network,
  ' then dump the results to "Offline.txt", else, dump it to "online.txt"
'*********************************************************************
  For Each objStatus in objPing
    If  IsNull(objStatus.ReplySize) Then
      ' Machine is offline --> dump the results to "Offline.txt"
      OfflineFile.Writeline strComputerName
    Else
      ' Machine is online  --> dump the results to "Online.txt"
      OnlineFile.Writeline strComputerName
    End If
  Next
   
  ' Destruye las variable de memoria
'*********************************************************************
  Set objPing=Nothing
  Set objStatus=Nothing

End Function


3  Programación / Scripting / Resolucion de IP y DNS - Powershell en: 31 Marzo 2013, 03:15 am
Hola, alguien me pueda ayudar. el problema es el siguiente que una no puedo resolverlo estoy un poco estancado.
Tengo que realizar un script que me resuleva el PING y DNS y toso esto escrtibirlo en un CSV. tengo hasta al momento el codigo pero aun no puedo armarlo dando tantas vueltas ya me quede un poco bloqueado. a ver si alguien mepuede ayudar gracias por todo.


Saludos

Código:
Clear
$log = "C:\log.log"
$output = @()
## Validar si el equipo hace PING
$PingMachines = Get-Content "C:\sql.txt"

ForEach($MachineName In $PingMachines){

    $PingStatus = Get-WmiObject Win32_PingStatus -Filter "Address = '$MachineName'" | Select-Object StatusCode
    #$tmp = New-Object Psobject -Property @{Name = $MachineName; Status = $PingStatus.StatusCode}
If ($PingStatus.StatusCode -eq 0){
$output += = "$machines - OK"
    }
Else{
    $output += = "$machines - NO_OK"
        }

## Validar si el equipo resuelve el DNS

$result = $null
    $currentEAP = $ErrorActionPreference
    $ErrorActionPreference = "silentlycontinue"
    $result = [System.Net.Dns]::GetHostbyName($MachineName)
    $ErrorActionPreference = $currentEAP
     
If($Result){
    $output += [string]$Result.HostName
}
Else{
    $output += = "$machines - No HostNameFound"
    }
 }
$output | Export-csv c:\export.csv -NoTypeInformation

4  Programación / Scripting / Re: [VBS] Problema al ejecutar un .EXE y crear su acceso directo en: 5 Mayo 2012, 18:25 pm
Graciassssssssss !!!!!!!!!!!!!!!
ya solucione el problema.

una consulta referente a programacion.
 
yo estoy comenzando con esto de VBSCRIPT y POwerShell pero no me aclaro mucho eh revisado los manuales publicados por este foro y estan muy bien pero aun no logro comprender muchas cosas.

tu me puedes orientar como puedo averiguar mas o si hay algun libro en español donde pueda aprovechar a sacarle todo el provecho.

saludos
5  Programación / Scripting / Re: [VBS] Problema al ejecutar un .EXE y crear su acceso directo en: 5 Mayo 2012, 17:42 pm
Hola. disculpa pero me sale el siguiente error, no se si esta bien lo que puse ya que en vbscript no tengo tantas nociones. el error es el siguiente.

.vbs(16, 1) Error de Microsoft VBScript en tiempo de ejecución: Variable no definida: 'strComputer' y el codigo es el siguiente.

Código
  1. '********************************************************************
  2. Option Explicit ' Declaracion de las variables
  3.  
  4. Dim Wshshell, Command
  5. Dim objShell, objDesktop, objLink 'Variables
  6. Dim strAppPath, strWorkDir, strIconPath 'Variables
  7. Dim srtComputer
  8.  
  9. ' ----------------------------------------------------------'
  10. ' Ejecuta el .EXE
  11.  
  12. Set Wshshell = Wscript.createObject("WScript.Shell")
  13. Command = "pspad454inst_en.exe" ' Mozilla.exe es un ejemplo como puede ser cualquier .EXE
  14. WshShell.Run Command ' Ejecuta el comando
  15.  
  16. strComputer = "."
  17. Set oWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  18.  
  19. ''# Create an event query to be notified within 5 seconds when Firefox is closed
  20. Set colEvents = oWMI.ExecNotificationQuery _
  21.    ("SELECT * FROM __InstanceDeletionEvent WITHIN 5 " _
  22.     & "WHERE TargetInstance ISA 'Win32_Process' " _
  23.     & "AND TargetInstance.Name = 'pspad454inst_en.exe'")
  24.  
  25. ''# Wait until Firefox is closed
  26. Set oEvent = colEvents.NextEvent
  27.  
  28.  
  29. ' Creación de Acceso Directo Aplicación
  30.  
  31. ' --------------------------------------------------
  32.  
  33.  
  34. strWorkDir ="z:\mozilla.exe" ' Directorio donde esta la aplicacion
  35. strAppPath = "d:\mozilla.exe" 'Ruta de la aplicación
  36.  
  37. Set objShell = CreateObject("WScript.Shell")
  38. objDesktop = objShell.SpecialFolders("D:\Users\Public\Desktop") ' Acceso directo en el escritorio
  39. Set objLink = objShell.CreateShortcut(objDesktop & "\COP - Comptabilitat Organisme Pagador.lnk") ' Nombre del acceso directo
  40.  
  41. ' ---------------------------------------------------
  42. 'Propiedades acceso ridercto
  43.  
  44. objLink.Description = "mozilla"   ' Comentario
  45. 'objLink.HotKey = "CTRL+SHIFT+X" ' Teclado de método abreviado
  46. objLink.TargetPath = strAppPath 'Ruta de la aplicación  (Destino)
  47. objLink.WindowStyle = 3
  48. objLink.WorkingDirectory = strWorkDir ' Directorio donde esta la aplicacion (Iniciar en)
  49. objLink.Save ' Guardar
  50.  
  51. WScript.Quit ' Salir
  52.  
  53. '********************************************************************
  54.  

saludos
6  Programación / Scripting / [VBS] Problema al ejecutar un .EXE y crear su acceso directo en: 5 Mayo 2012, 15:56 pm
Hola a todos,

tengo un problema que aun no me puedo aclarar debe ser algo simple pero no da mi cabeza para mas, estoy bloqueado. El problema que tengo es el siguiente.
tengo un Script que realiza lo siguiente.

instala un programa el ejecutable es un .exe
una vez termine de ejecutar como no te hace una acceso directo, lo genero yo. pero el problema es que realiza la primera instruccion y a la misma vez la instruccion del acceso directo. pero como aun no termina la ejecucion del .exe no puede generar el acceso directo. solo me hace la primera parte.
este es el script. alguien me puede dar alguna orientacion

Código
  1.  
  2. ********************************************************************
  3. Option Explicit ' Declaracion de las variables
  4.  
  5. Dim Wshshell, Command
  6. Dim objShell, objDesktop, objLink 'Variables
  7. Dim strAppPath, strWorkDir, strIconPath 'Variables
  8.  
  9. ' ----------------------------------------------------------'
  10. ' Ejecuta el .EXE
  11.  
  12. Set Wshshell = Wscript.createObject("WScript.Shell")
  13. Command = "mozilla.exe" ' Mozilla.exe es un ejemplo como puede ser cualquier .EXE
  14. WshShell.Run Command ' Ejecuta el comando
  15.  
  16.  
  17. ' Creación de Acceso Directo Aplicación
  18.  
  19. ' --------------------------------------------------
  20.  
  21.  
  22. strWorkDir ="z:\mozilla.exe" ' Directorio donde esta la aplicacion
  23. strAppPath = "d:\mozilla.exe" 'Ruta de la aplicación
  24.  
  25. Set objShell = CreateObject("WScript.Shell")
  26. objDesktop = objShell.SpecialFolders("D:\Users\Public\Desktop") ' Acceso directo en el escritorio
  27. Set objLink = objShell.CreateShortcut(objDesktop & "\COP - Comptabilitat Organisme Pagador.lnk") ' Nombre del acceso directo
  28.  
  29. ' ---------------------------------------------------
  30. 'Propiedades acceso ridercto
  31.  
  32. objLink.Description = "mozilla"   ' Comentario
  33. 'objLink.HotKey = "CTRL+SHIFT+X" ' Teclado de método abreviado
  34. objLink.TargetPath = strAppPath 'Ruta de la aplicación  (Destino)
  35. objLink.WindowStyle = 3
  36. objLink.WorkingDirectory = strWorkDir ' Directorio donde esta la aplicacion (Iniciar en)
  37. objLink.Save ' Guardar
  38.  
  39. WScript.Quit ' Salir
  40.  
  41.  
  42. ********************************************************************
  43.  
Saludos y espero alguna orientacion
7  Programación / Scripting / Re: Mapeo de impresoras en red por usuarioa en: 1 Mayo 2011, 12:01 pm
Hola,

Alguien me puede ayudar ??
8  Programación / Scripting / Re: Mapeo de impresoras en red por usuarioa en: 28 Abril 2011, 22:18 pm
Hola,

eh estado revisando y es lo que tengo hasta el momento en algo me equivoco al momento de conectar

Elimina correctamente, hace el array pero no puedo agregarlo a ver si alguien me ayuda.

Gracias por la pasciencia.

-------------------------------------------------------------------------

'Set global script objects and variables
Set wshShell = WScript.CreateObject("WScript.Shell")
Set wshNetwork = WScript.CreateObject("WScript.Network")
Set wshObj = WScript.CreateObject("Scripting.FileSystemObject")

'Variables
strNetworkPath = "C:\Copia de impresoras1.txt"


'-----------------------------------------------------------------------------'
Eliminar impresora

'On Error Resume Next

Call DisconnectNetworkPrinters()
MsgBox "Ejecuta asignar prn"
Call ConnectPrinters(strNetworkPath, wshNetwork.computername)

Sub DisconnectNetworkPrinters()
  Set arPrinters = wshNetwork.EnumPrinterConnections

  For i = 0 to (arPrinters.Count - 1) Step 2
    If (Left(arPrinters.Item(i + 1), 2) = "\\") Then
      wshNetwork.RemovePrinterConnection arPrinters.Item(i + 1)
    End If
  Next
End Sub

'--------------------------------------------------------------------------------'
Conectar impresoras

Sub ConnectPrinters(strListFile, strCompname)
Dim arrLinParts()
Dim strCadTratar
  Set ListFile = wshObj.OpenTextFile(strListFile, 1)
 
  Do While ListFile.AtEndOfStream <> True
    strCadTratar = ListFile.ReadLine
    arrLineParts = Split(strCadTratar, Space(1))
   
    MsgBox strCompname & " " & strCadTratar
    If UCase(strCompname) = UCase(arrLineParts(0)) Then
   
      For i = 0 To UBound(arrLineParts)
        If arrLineParts(i) <> "" Then
          wshNetwork.AddWindowsPrinterConnection UCase(arrLineParts(i))
        End If
      Next
     
      If arrLineParts(1) <> "" Then
        wshNetwork.SetDefaultPrinter UCase(arrLineParts(1))
      End If
    End If
  Loop
 
  ListFile.Close
End Sub
9  Programación / Scripting / Re: Mapeo de impresoras en red por usuarioa en: 28 Abril 2011, 21:00 pm
Hola,
si lo ejecute con permisos pero el error continua lo que hice fue lo siguiente.

Eliminar impresoras de RED
 
strComputer = "."
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    Set objShell = CreateObject("Wscript.Shell")
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colInstalledPrinters = objWMIService.ExecQuery _
    ("Select * from Win32_Printer")
    For Each objPrinter in colInstalledPrinters
     if InStr(objPrinter.Name, "\\")> 0 then
        WshNetwork.RemovePrinterConnection objPrinter.Name
    end if
    Next

Ahora me falta agregarlas.

eh estado probando que leea desde un archivo plano pero no puedo lograrlo
es decir tengo el siguiente txt.

ouprueba1 \\server\printer
ouprueba2 \\server\printer
ouprueba3 \\server\printer

quiero que leea este archivo y lo compare con las ou que tengo en el active directory si pertenece el ou comparando con el txt que agregue la impresora.

a ver si me puedes ayudar yo sigo probando y te comento mis avances.

saludos
10  Programación / Scripting / Re: Mapeo de impresoras en red por usuarioa en: 28 Abril 2011, 00:52 am
Hola,

ya revise los permisos y estan correcto pero no logro que el error no salga, no me elimina las impresoras que tengo mapeadas para luego agregarlas, ufff debe ser algo tonto pero no lo veo aun.

saludos
Páginas: [1] 2 3
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines