Hi mal wieder ich mit einem neuen Problem
Vieleicht kann ich irgendwann auch mal helfen xD
Also ich habe folgendes Problem ich habe im Form Load eine Ip adressen abzeige wenn ich das Programm nun Starte ist die ganze Form so lange eingefroren bis die Ip adresse geladen wurd Wie kann ich das einfreieren vermeiden?
Code in Form Load
Generierung der IP Abfrage
Vieleicht kann ich irgendwann auch mal helfen xD
Also ich habe folgendes Problem ich habe im Form Load eine Ip adressen abzeige wenn ich das Programm nun Starte ist die ganze Form so lange eingefroren bis die Ip adresse geladen wurd Wie kann ich das einfreieren vermeiden?
Code in Form Load
Generierung der IP Abfrage
VB.NET-Quellcode
- Public Shared Function GetIP(Optional ByVal fritzBox As Boolean = False) As String
- Dim str As String
- If (Not fritzBox) Then
- Dim str1 As String = "0.0.0.0"
- Try
- Dim str2 As String = ""
- str2 = (New WebClient()).DownloadString("http://checkip.dyndns.org")
- Dim strArrays As String() = str2.Split(New String() {":", "<"}, StringSplitOptions.RemoveEmptyEntries)
- str1 = strArrays(6).Trim()
- Catch exception As System.Exception
- str = str1
- Return str
- End Try
- str = str1
- Else
- Dim httpWebRequest As System.Net.HttpWebRequest = DirectCast(WebRequest.Create("http://fritz.box:49000/igdupnp/control/WANIPConn1"), System.Net.HttpWebRequest)
- Dim length As System.Net.HttpWebRequest = httpWebRequest
- length.Method = "POST"
- length.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0"
- length.Headers.Add("SOAPACTION", "urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIPAddress")
- length.ContentType = "text/xml; charset=UTF-8"
- length.ContentLength = CLng(297)
- length.Timeout = 60000
- length.AllowAutoRedirect = True
- Dim str3 As String = String.Concat(New String() {"<?xml version=""1.0"" encoding=""utf-8""?>", Environment.NewLine, "<s:Envelope s:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"">", Environment.NewLine, " <s:Body>", Environment.NewLine, " <u:GetExternalIPAddress xmlns:u=""urn:schemas-upnp-org:service:WANIPConnection:1"" />", Environment.NewLine, " </s:Body>", Environment.NewLine, "</s:Envelope>"})
- If (str3.Length <= 0) Then
- str = "0.0.0.0"
- Else
- length.ContentLength = CLng(CInt(Encoding.UTF8.GetBytes(str3).Length))
- Dim requestStream As Stream = httpWebRequest.GetRequestStream()
- requestStream.Write(Encoding.UTF8.GetBytes(str3), 0, CInt(Encoding.UTF8.GetBytes(str3).Length))
- requestStream.Close()
- Dim response As HttpWebResponse = DirectCast(length.GetResponse(), HttpWebResponse)
- str = Regex.Split(Regex.Split((New StreamReader(response.GetResponseStream())).ReadToEnd(), "<NewExternalIPAddress>")(1), "</NewExternalIPAddress>")(0)
- End If
- End If
- Return str
- End Function