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

 

 


Tema destacado: Curso de javascript por TickTack


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  A que lenguaje traduzco un Script hecho en linux
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 [2] Ir Abajo Respuesta Imprimir
Autor Tema: A que lenguaje traduzco un Script hecho en linux  (Leído 9,454 veces)
desorder

Desconectado Desconectado

Mensajes: 54



Ver Perfil
Re: A que lenguaje traduzco un Script hecho en linux
« Respuesta #10 en: 4 Mayo 2007, 11:07 am »

Neox, gracias por el codigo que has posteado, en cuanto tenga un momento lo pruebo.
De todas formas sigo intentando hacerlo en vbscript ya solo por cabezoneria

Una ultima pregunta,¿Como hariais para ejecutar este programa en win, ya que lo que quiero es que se ejecute desde que se inicia windows y que se ejecute cada x tiempo para comprobar que el pc no se queda sin red?
Lo que he pensado es ejecutarlo a traves de una tarea programada

¿Se os ocurre alguna otra idea?
Salu2


En línea

ne0x

Desconectado Desconectado

Mensajes: 270



Ver Perfil
Re: A que lenguaje traduzco un Script hecho en linux
« Respuesta #11 en: 4 Mayo 2007, 15:05 pm »

Pues a mi en Batch si, supongo que lo podras aplicar a VBScript.

Agregas una clave en el registro para que se inicie siempre con el PC o lo copias en la carpeta de inicio.

Y usas el comando AT para que por ejemplo en la proxima media hora ejecute el script.


En línea

desorder

Desconectado Desconectado

Mensajes: 54



Ver Perfil
Re: A que lenguaje traduzco un Script hecho en linux
« Respuesta #12 en: 4 Mayo 2007, 16:03 pm »

gracias neox por la ayuda que me has prestado

En general gracias a todos

salu2
En línea

desorder

Desconectado Desconectado

Mensajes: 54



Ver Perfil
Re: A que lenguaje traduzco un Script hecho en linux
« Respuesta #13 en: 29 Mayo 2007, 16:08 pm »

hola a todos,,

Sigo peleandome con el dichoso script en VB Script.

Tengo el siguiente problema al intentar hacer ping con el siguiente codigo:

If Reachable("169.254.0.22") Then
 WScript.Echo "Computer is Reachable!"
Else
 'WScript.Echo "Computer is Unreachable!"
End If

Function Reachable(strComputer)
 Set objShell = Wscript.CreateObject("Wscript.Shell")
 objShell.exec ("%comspec% /k ping 169.254.0.22") & " > c:\t.txt"
End Function

Cuando se ejecuta esta linea "objShell.exec ("%comspec% /k ping 169.254.0.22") & " > c:\t.txt" no se consigue hacer ping, es decir parece que no se lanza la utilidad ping, se crea el archivo de texto t.txt y este aparece vacio

pero por el contrario si ejecutas
objShell.exec ("%comspec% /k ipconfig") & " > c:\t.txt"
entonces este comando si se ejecuta y si redireciona el contenido de este al archivo de texto

He probado con otros comandos como el net view y tb funciona

Tb he probado con el comando run:objShell.Run ("%comspec% /k ping 169.254.0.22") & " > c:\t.txt" y tampoco funciona

No se porque ciertos comandos si se ejecutan y otros no, alguien sabe por que puede ser??

NOTA: el comando objShell.exec ("%comspec% /k ping 169.254.0.22") & " > c:\t.txt" funciona bien porque lo he probado desde inicio ejecutar y se lanza sin problemas

Por favor os pediria que si podeis probeis el codigo de arriba en algun pc que tenga win 2000 o XP, yo lo he probado en ambos SO y en ninguno me ha funcionado y me parece extraño porque todo lo que he encontrado sobre como realizar un ping desde vb Script, incluido el technet de microsoft, indica que se realiza asi sin problemas

PD: una advertencia, al ejecutar el codigo de arriba sobre win 2000 me empezaba a abrir cientos de ventanas de msdos , casi bloqueandome el equipo, asi que ojo si lo probais!!

salu2





"
En línea

ne0x

Desconectado Desconectado

Mensajes: 270



Ver Perfil
Re: A que lenguaje traduzco un Script hecho en linux
« Respuesta #14 en: 29 Mayo 2007, 18:04 pm »

Mira esto a ver si te sirve:

:: Autor: pantocrator
:: MAs información: http://pantocrator-blog.blogspot.com/

Código:
@Echo OFF
echo [requerido] Primer parametro %1 es para ip estatica.
echo [requerido] Segundo parametro %2 es la mascara de red.
echo [requerido] Tercer parametro %3 es la puerta de enlace.
echo [opcional] Cuarto parametro %4 es el servidor dns primario
If [%1] == [] GOTO QUIT
If [%2] == [] GOTO QUIT
If [%3] == [] GOTO QUIT
echo Starting %0
Echo ....................Configurando IP address en Conexi¢n de rea local a %1 con NetMask %2
netsh interface ip set address name="Conexi¢n de rea local" source=static addr=%1 mask=%2
Echo ....................Configurando Gateway en Conexi¢n de rea local a %3
netsh interface ip set address name="Conexi¢n de rea local" gateway=%3 gwmetric=1
If [%4] == [] GOTO QUIT
Echo ....................Configurando DNS en Conexi¢n de rea local a %4
netsh interface ip set dns name="Conexi¢n de rea local" source=static addr=%4 register=primary
GOTO QUIT

:QUIT
ECHO ON
En línea

desorder

Desconectado Desconectado

Mensajes: 54



Ver Perfil
Re: A que lenguaje traduzco un Script hecho en linux
« Respuesta #15 en: 30 Mayo 2007, 12:55 pm »

neox gracias por ese codigo, pero no me sirve ya que para cambiar ip, dns o gw no tengo problema desde VB, el problema lo tenia haciendo ping pero ya he dado con el problema que era el siguiente; en la linea
" objShell.exec ("%comspec% /k ping 169.254.0.22") & " > c:\t.txt" "

falta añadirle al comando ping el p..ñ...tero .exe quedando de esta forma

objShell.exec ("%comspec% /k ping.exe 169.254.0.22") & " > c:\t.txt"

No se por que sin el .exe no funciona, ya que todos los codigos que he visto estaban sin el, pero bueno que se le va a hacer

de todas formas agradezco tu codigo porque no conocia el comando netsh y me parece bastante interesante y util

Cuando tenga todo el codigo del script lo posteo por si le puede interesar a alguien
salu2

En línea

desorder

Desconectado Desconectado

Mensajes: 54



Ver Perfil
Re: A que lenguaje traduzco un Script hecho en linux
« Respuesta #16 en: 5 Junio 2007, 16:54 pm »

ahi os queda el codigo del script en vb script por si le interesa a alguien


Dim DefaultGw,GwR,GwTel

GwR="169.254.0.27"
GwTel="169.254.0.200"
If RedUp Then
   If Reachable("169.254.0.8") Then
       'WScript.Echo "Computer is Reachable!"
   Else
       gw
       If Reachable(DefaultGw) Then
          CambiaGw
       Else
    
          If DefaultGw=GwR Then
             If Reachable(GwTel) Then
                CambiaGw
             Else
                WScript.Echo "Fallo en la red. Comprobar cable de red"
             End If
          ElseIf DefaultGw=GwTel Then
        
             If Reachable(GwR) Then
                CambiaGw
             Else
                WScript.Echo "Fallo en la red. Comprobar cable de red"
             End If
           
          End If
          
       End If
 
   End If
   
End If

'''''''''''''''''''''''''''''''''''PING''''''''''''''''''''''''''''''''''''''''''
Function Reachable(strComputer)

   Set objShell = Wscript.CreateObject("Wscript.Shell")
   Set objExecObject = objShell.Exec ("cmd /C ping.exe -n 4 " & strComputer )

   Do While Not objExecObject.StdOut.AtEndOfStream
       strText = objExecObject.StdOut.ReadLine()
       If (Instr(strText, "perdidos = 0") > 0) Or (Instr(strText, "perdidos = 1") > 0) Then
           Reachable=true
           Exit Do
       End If
   Loop

End Function
''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''obtener gw''''''''''''''''''''''''
sub gw ()

   strComputer = "."
   Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

   Set DefaultGW = objWMIService.ExecQuery _
    ("Select DefaultIPGateway from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
 
   For Each DfGw In DefaultGW
       If Not IsNull(DfGw.DefaultIPGateway) Then
           For i=LBound(DfGw.DefaultIPGateway) to UBound(DfGw.DefaultIPGateway)
               
               DefaultGw=DfGw.DefaultIPGateway(i)
               
           Next
       End If
   Next
   
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''COMPROBAR SI LA INTERFAZ ESTA UP'''''''''''''''''''''
Function RedUp()

   strComputer = "."
   Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

   Set DefaultGW = objWMIService.ExecQuery _
    ("Select DefaultIPGateway from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
   
   For Each DfGw In DefaultGw
       If  IsNull(DfGw.DefaultIPGateway) Then
         WScript.Echo "Fallo en la red. Comprobar cable de red"
      Else
         RedUp=True
      End If
   Next

End Function

'''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''CAMBIAR GW''''''''''''''''
Function CambiaGw
   
   strComputer = "."
   Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

   Set colNetCards = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")

   For Each objNetCard in colNetCards
      WScript.Echo "vamos a cambiar a ..." & DefaultGw
       If DefaultGw=GwR Then
          arrGateways = Array(GwTel)
          objNetCard.SetGateways(arrGateways)
       ElseIf DefaultGw=GwTel Then
          arrGateways = Array(GwR)
          objNetCard.SetGateways(arrGateways)
       End If
   Next
   
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''

saludos
En línea

Páginas: 1 [2] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines