Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2009
    Messaggi
    82

    [VB 08]Riportare Ip in un label

    In poche parole vorrei creare un'applicazione dove dovrebbe essercci un pulsante e un label, quando si clicca sul pulsante dovrà apparire nel label l'indirizzo ip del computer... Quello che è in corrispontenza di Intirizzo Ip quando si scrive sul prompt dei comandi "ipconfig /all". Sapete darmi un aiuto? grz..

  2. #2
    Utente di HTML.it
    Registrato dal
    Jan 2007
    Messaggi
    172
    Io uso questa funzione.

    Public Function getIPstring() As String
    'This downloads the source of whatismyip.com
    Dim wclient As New System.Net.WebClient
    Try
    'Download the source to the temp path
    wclient.DownloadFile("http://www.findmyipaddress.com//", Application.StartupPath & "\Temp\ip.txt")
    Catch
    'If there is a problem it will be caught and will return and error message
    Dim errorString As String = "Unable to get IP."
    Return errorString
    Exit Function
    End Try

    'This creates the filestream and streamreader that is used to read the source
    Dim FS As New System.IO.FileStream(Application.StartupPath & "\Temp\ip.txt", IO.FileMode.Open)
    Dim SR As New System.IO.StreamReader(FS)

    'Here is where we start looking for the ip. This is the line we are trying to find.
    '<h1> Your IP is XXX.XXX.XXX.XXX
    </h1>

    'This puts the entire file into a string
    Dim entirefile As String = SR.ReadToEnd

    'This gets the starting position of the ip address
    Dim startIndex As Integer = entirefile.IndexOf("My IP Address")

    'This reads 15 characters from the begginning of the ip
    Dim restOfTheLine As String = entirefile.Substring(startIndex + 15, 15)

    'If the ip is shorter that 15 characters this cuts off any extra characters
    Dim theIp As String = restOfTheLine.TrimEnd("<", ">", "b", "r", "/", "h", "1", " ")

    'Close the filestream and streamreader
    SR.Close()
    FS.Close()

    'Dispose of the source once we get out ip in a String
    Kill(Application.StartupPath & "\Temp\ip.txt")
    Labelip.Text = (theIp)
    Config.LabelIp.Text = (theIp)
    'Return the ip in string format
    Return theIp

    End Function

  3. #3
    Utente di HTML.it
    Registrato dal
    Jan 2009
    Messaggi
    82
    Scusami tanto la domanda ma questo lo dovrei mettere nella classe che definisce il click del pulsante?

  4. #4
    Utente di HTML.it
    Registrato dal
    Jan 2007
    Messaggi
    172
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    getIPstring()

    End Sub



    Public Function getIPstring() As String
    'This downloads the source of whatismyip.com
    Dim wclient As New System.Net.WebClient
    Try
    'Download the source to the temp path
    wclient.DownloadFile("http://www.findmyipaddress.com//", Application.StartupPath & "\Temp\ip.txt")
    Catch
    'If there is a problem it will be caught and will return and error message
    Dim errorString As String = "Unable to get IP."
    Return errorString
    Exit Function
    End Try

    'This creates the filestream and streamreader that is used to read the source
    Dim FS As New System.IO.FileStream(Application.StartupPath & "\Temp\ip.txt", IO.FileMode.Open)
    Dim SR As New System.IO.StreamReader(FS)

    'Here is where we start looking for the ip. This is the line we are trying to find.
    '<h1> Your IP is XXX.XXX.XXX.XXX
    </h1>

    'This puts the entire file into a string
    Dim entirefile As String = SR.ReadToEnd

    'This gets the starting position of the ip address
    Dim startIndex As Integer = entirefile.IndexOf("My IP Address")

    'This reads 15 characters from the begginning of the ip
    Dim restOfTheLine As String = entirefile.Substring(startIndex + 15, 15)

    'If the ip is shorter that 15 characters this cuts off any extra characters
    Dim theIp As String = restOfTheLine.TrimEnd("<", ">", "b", "r", "/", "h", "1", " ")

    'Close the filestream and streamreader
    SR.Close()
    FS.Close()

    'Dispose of the source once we get out ip in a String
    Kill(Application.StartupPath & "\Temp\ip.txt")
    Labelip.Text = (theIp)
    Config.LabelIp.Text = (theIp)
    'Return the ip in string format
    Return theIp

    End Function

  5. #5
    Utente di HTML.it
    Registrato dal
    Jan 2009
    Messaggi
    82
    Ho risolto usando un'altro tipo di codice che ho sviluppato capendo come funziona System.Net. Grazie per l'aiuto

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.