Trovare l'indirizzo IP del client in vb.net
Per determinare l'indirizzo IP del client si sfrutta l'istruzione Request.UserHostAddress:
Qui di seguito il codice html che inseriremo nel file YourIP.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="YourIP.aspx.vb" Inherits="YourIP" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Your IP</title> </head> <body> <form id="form1" runat="server"> <div id="divIpInfo" runat="server" ></div> </form> </body> </html>
|
e ora il codice vb che inseriremo nel file YourIP.aspx.vb
Partial Class YourIP Inherits System.Web.UI.Page Protected Sub form1_Load(sender As Object, e As EventArgs) Handles form1.Load Dim IP As String IP = Request.UserHostAddress If IP = "::1" Or IP = "127.0.0.1" Then divIpInfo.InnerText = "Non è possibile determinare il tuo indirizzo perchè sei nella stessa lan del server" Else divIpInfo.InnerText = "Il tuo indirizzo è: " & IP End If End Sub End Class
|