【VISUAL VB.NET】IP Address

Imports System Imports System.Collections.Generic Imports System.ComponentModel Imports System.Data Imports System.Drawing Imports System.Linq Imports System.Text Imports System.Threading.Tasks Imports System.Windows.Forms ' make sure that using System.Diagnostics; is included Imports System.Diagnostics ' make sure that using System.Security.Principal; is included Imports System.Security.Principal ' need namespace System.Net; Imports System.Net ' need namespace System.IO; Imports System.IO ' need namespace System.Net.Sockets; Imports System.Net.Sockets Public Class Form1 Public Sub New() MyBase.New() InitializeComponent() listBox1.Items.Add(LocalIPAddress().ToString()) label2.Text = GetPublicIP().ToString() End Sub Public Function LocalIPAddress() As String Dim host As IPHostEntry Dim localIP As String = "" host = Dns.GetHostEntry(Dns.GetHostName()) For Each ip As IPAddress In host.AddressList If ip.AddressFamily = AddressFamily.InterNetwork Then localIP = ip.ToString() Exit For End If Next Return localIP End Function Public Function GetPublicIP() As String Dim direction As [String] = "" Dim request As WebRequest = WebRequest.Create("http://checkip.dyndns.org/") Using response As WebResponse = request.GetResponse() Using stream As New StreamReader(response.GetResponseStream()) direction = stream.ReadToEnd() End Using End Using 'Search for the ip in the html Dim first As Integer = direction.IndexOf("Address: ") + 9 Dim last As Integer = direction.LastIndexOf("</body>") direction = direction.Substring(first, last - first) Return direction End Function #Region "basic function for app" Private Sub lblLink_Click_1(sender As Object, e As EventArgs) Handles lblLink.Click Process.Start("www.vclexamples.com") End Sub Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean If (keyData = Keys.Escape) Then Me.Close() Return True End If Return MyBase.ProcessCmdKey(msg, keyData) End Function #End Region End Class

No comments:

Top 3 UX Design Articles of 2024 to Remember

Based on most subscriptions ͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­...

Contact Form

Name

Email *

Message *