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

 

 


Tema destacado:


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Cambiar una página por otra Visual Basic
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Cambiar una página por otra Visual Basic  (Leído 2,460 veces)
Adrylek

Desconectado Desconectado

Mensajes: 26


Ver Perfil
Cambiar una página por otra Visual Basic
« en: 10 Agosto 2013, 00:32 am »

Me gustaría saber si hay alguna manera para cambiar una página por otra, es decir, al ir a google, que salga youtube (por ejemplo), como lo hace el Fiddler.

Gracias..


En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.810



Ver Perfil
Re: Cambiar una página por otra Visual Basic
« Respuesta #1 en: 10 Agosto 2013, 10:18 am »

¿Puedes ser más específico?, ¿Pretendes hacerlo en tiempo de ejecución en un WebBrowser Control?, ¿O pretendes que los cambios sean permanentes en el PC con cualquier navegador?.

Para lo segundo es tán sencillo como añadir una entrada el archivo HOSTS. http://msdn.microsoft.com/en-us/library/ff749174.aspx

EDITO: Y para lo primero puedes checkar la url del control para modificarla por la que quieras.

Código
  1.    Private Sub WebBrowser1_Navigated(sender As Object, e As WebBrowserNavigatedEventArgs) _
  2.    Handles WebBrowser1.Navigated
  3.  
  4.            Select Case True
  5.  
  6.                Case sender.url.ToString.ToLower.StartsWith("http://www.google")
  7.                    sender.navigate("youtube.com")
  8.  
  9.                Case Else
  10.                    ' MsgBox(sender.url.ToString.ToLower)
  11.  
  12.            End Select
  13.  
  14.    End Sub

Saludos



« Última modificación: 10 Agosto 2013, 10:38 am por EleKtro H@cker » En línea

Adrylek

Desconectado Desconectado

Mensajes: 26


Ver Perfil
Re: Cambiar una página por otra Visual Basic
« Respuesta #2 en: 10 Agosto 2013, 18:44 pm »

¿Puedes ser más específico?, ¿Pretendes hacerlo en tiempo de ejecución en un WebBrowser Control?, ¿O pretendes que los cambios sean permanentes en el PC con cualquier navegador?.

Para lo segundo es tán sencillo como añadir una entrada el archivo HOSTS. http://msdn.microsoft.com/en-us/library/ff749174.aspx

EDITO: Y para lo primero puedes checkar la url del control para modificarla por la que quieras.

Código
  1.    Private Sub WebBrowser1_Navigated(sender As Object, e As WebBrowserNavigatedEventArgs) _
  2.    Handles WebBrowser1.Navigated
  3.  
  4.            Select Case True
  5.  
  6.                Case sender.url.ToString.ToLower.StartsWith("http://www.google")
  7.                    sender.navigate("youtube.com")
  8.  
  9.                Case Else
  10.                    ' MsgBox(sender.url.ToString.ToLower)
  11.  
  12.            End Select
  13.  
  14.    End Sub

Saludos


Quiero que los cambios sean permanentes en la PC en cualquier navegador, pero que se quiten al desmarcar la checkbox..
En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.810



Ver Perfil
Re: Cambiar una página por otra Visual Basic
« Respuesta #3 en: 10 Agosto 2013, 22:55 pm »

Quiero que los cambios sean permanentes en la PC

es tán sencillo como añadir una entrada el archivo HOSTS. http://msdn.microsoft.com/en-us/library/ff749174.aspx

Acabo de codear una Class para manipular el archivo Hosts, puedes agregar un nuevo mapeo, bloquear diréctamente una url, eliminar un mapeo ...sólamente lo he testeado lo necesario.

Aquí tienes ;):

Código
  1. #Region " Hosts Helper "
  2.  
  3. Public Class Hosts_Helper
  4.  
  5.  
  6.    ' [ Hosts Helper ]
  7.    '
  8.    ' // By Elektro H@cker
  9.    '
  10.    ' Examples:
  11.    '
  12.    ' MsgBox(Hosts_Helper.HOSTS_Exists)
  13.    ' Hosts_Helper.Add("www.youtube.com", "231.7.66.33")
  14.    ' Hosts_Helper.Block("www.youtube.com")
  15.    ' MsgBox(Hosts_Helper.IsAdded("www.youtube.com"))
  16.    ' MsgBox(Hosts_Helper.IsBlocked("www.youtube.com"))
  17.    ' Hosts_Helper.Remove("www.youtube.com")
  18.    ' Hosts_Helper.Clean_Hosts_File()
  19.  
  20.  
  21.    Shared ReadOnly HOSTS As String = _
  22.    IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "Drivers\etc\hosts")
  23.  
  24.  
  25.    ''' <summary>
  26.    ''' Adds a new Block mapping into the Hosts file.
  27.    ''' </summary>
  28.    Public Shared Sub Block(ByVal URL As String)
  29.  
  30.        Dim Entry As String = String.Format("::1 {0}", URL)
  31.  
  32.        If HOSTS_Exists() AndAlso IsBlocked(URL) Then
  33.  
  34.            Throw New Exception(String.Format("""{0}"" is already blocked.", URL))
  35.            Exit Sub
  36.  
  37.        ElseIf HOSTS_Exists() AndAlso IsAdded(URL) Then
  38.  
  39.            Remove(URL)
  40.  
  41.        End If
  42.  
  43.        Try
  44.            IO.File.AppendAllText(HOSTS, (Environment.NewLine & Entry), System.Text.Encoding.Default)
  45.        Catch ex As Exception
  46.            Throw New Exception(ex.Message)
  47.        End Try
  48.  
  49.    End Sub
  50.  
  51.  
  52.    ''' <summary>
  53.    ''' Adds a new mapping into Hosts file.
  54.    ''' </summary>
  55.    Public Shared Sub Add(ByVal URL As String, ByVal IP_Address As String)
  56.  
  57.        Dim Entry As String = String.Format("{0} {1}", IP_Address, URL)
  58.  
  59.        If HOSTS_Exists() AndAlso (IsAdded(URL) OrElse IsBlocked(URL)) Then
  60.            Throw New Exception(String.Format("""{0}"" is already mapped.", URL))
  61.            Exit Sub
  62.  
  63.        ElseIf Not Validate_IP(IP_Address) Then
  64.            Throw New Exception(String.Format("""{0}"" is not a valid IP adress.", IP_Address))
  65.            Exit Sub
  66.        End If
  67.  
  68.        Try
  69.            IO.File.AppendAllText(HOSTS, (Environment.NewLine & Entry), System.Text.Encoding.Default)
  70.        Catch ex As Exception
  71.            Throw New Exception(ex.Message)
  72.        End Try
  73.  
  74.    End Sub
  75.  
  76.  
  77.    ''' <summary>
  78.    ''' Removes a blocked or an added URL from the Hosts file.
  79.    ''' </summary>
  80.    Public Shared Sub Remove(ByVal URL As String)
  81.  
  82.        If Not HOSTS_Exists() Then
  83.            Throw New Exception("HOSTS File does not exists.")
  84.            Exit Sub
  85.        ElseIf HOSTS_Exists() And Not (IsAdded(URL) OrElse IsBlocked(URL)) Then
  86.            Throw New Exception(String.Format("""{0}"" is not added yet.", URL))
  87.            Exit Sub
  88.        End If
  89.  
  90.        Try
  91.  
  92.            Dim Content As String = _
  93.                System.Text.RegularExpressions.Regex.Replace(IO.File.ReadAllText(HOSTS).ToLower, _
  94.                String.Format("(\d{{1,3}}\.\d{{1,3}}\.\d{{1,3}}\.\d{{1,3}}|::1)(\s+|\t+){0}", URL.ToLower), String.Empty)
  95.  
  96.            IO.File.WriteAllText(HOSTS, Content, System.Text.Encoding.Default)
  97.  
  98.        Catch ex As Exception
  99.            Throw New Exception(ex.Message)
  100.        End Try
  101.  
  102.    End Sub
  103.  
  104.  
  105.    ''' <summary>
  106.    ''' Checks if an URL is already added into the Hosts file.
  107.    ''' </summary>
  108.    Public Shared Function IsAdded(ByVal URL As String) As Boolean
  109.  
  110.        Return If(Not HOSTS_Exists(), False, _
  111.                  System.Text.RegularExpressions.Regex.IsMatch( _
  112.                  System.Text.RegularExpressions.Regex.Replace(IO.File.ReadAllText(HOSTS).ToLower, "\s+|\t+", ";"), _
  113.                  String.Format(";[^\#]?\d{{1,3}}\.\d{{1,3}}\.\d{{1,3}}\.\d{{1,3}};{0}", URL.ToLower)))
  114.  
  115.    End Function
  116.  
  117.  
  118.    ''' <summary>
  119.    ''' Checks if an URL is already blocked into the Hosts file.
  120.    ''' </summary>
  121.    Public Shared Function IsBlocked(ByVal URL As String) As Boolean
  122.  
  123.        Return If(Not HOSTS_Exists(), False, _
  124.                  System.Text.RegularExpressions.Regex.IsMatch( _
  125.                  System.Text.RegularExpressions.Regex.Replace(IO.File.ReadAllText(HOSTS).ToLower, "\s+|\t+", String.Empty), _
  126.                  String.Format("[^\#](127.0.0.1|::1){0}", URL.ToLower)))
  127.  
  128.    End Function
  129.  
  130.  
  131.    ''' <summary>
  132.    ''' Checks if the Hosts file exists.
  133.    ''' </summary>
  134.    Public Shared Function HOSTS_Exists() As Boolean
  135.        Return IO.File.Exists(HOSTS)
  136.    End Function
  137.  
  138.  
  139.    ''' <summary>
  140.    ''' Cleans all the mappings inside the Hosts file.
  141.    ''' </summary>
  142.    Public Shared Sub Clean_Hosts_File()
  143.        Try
  144.            IO.File.WriteAllText(HOSTS, String.Empty)
  145.        Catch ex As Exception
  146.            MsgBox(ex.Message)
  147.        End Try
  148.    End Sub
  149.  
  150.  
  151.    ' Validates an IP adress.
  152.    Private Shared Function Validate_IP(ByVal IP_Address As String) As Boolean
  153.        Dim IP As System.Net.IPAddress = Nothing
  154.        Return System.Net.IPAddress.TryParse(IP_Address, IP)
  155.    End Function
  156.  
  157. End Class
  158.  
  159. #End Region

De nada  :P
« Última modificación: 10 Agosto 2013, 23:16 pm por EleKtro H@cker » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

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