Partial Class _default
Inherits System.Web.UI.Page
Function UDPCommunication(ByVal input As String) As String
Dim result As String = "!false"
Dim udp As New System.Net.Sockets.UdpClient(0)
Dim ip As New System.Net.IPEndPoint(System.Net.IPAddress.Parse(GetUrlHostIp("花生壳域名")), 3389)
Dim bytes() As Byte = System.Text.Encoding.Unicode.GetBytes(input)
udp.Send(bytes, bytes.Length, ip) '发送数据
Dim sdt As Date = Date.Now
While Date.Now < sdt.AddSeconds(1) '等1秒
If udp.Available > 0 Then
Dim remoteIp As New System.Net.IPEndPoint(System.Net.IPAddress.Any, 0)
Dim rbytes() As Byte = udp.Receive(remoteIp)
result = System.Text.Encoding.Unicode.GetString(rbytes) '获取返回值
End If
End While
udp.Close()
If result <> "!false" Then Exit For
Return result
End Function
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim rf As String = Text4.Value
If rf IsNot Nothing Then
Dim r As String = UDPCommunication("%" & rf & "%")
Dim c() As String = r.Trim("%").Split("$")
Dim s() As String = c(0).Split("%")
Text1.Value = s(0)
Text2.Value = s(1)
Text3.Value = s(2)
End If
End Sub
Public Shared Function GetUrlHostIp(s_host As String) As String
Try
Dim ipHost = Dns.GetHostEntry(s_host)
For Each ip As System.Net.IPAddress In ipHost.AddressList
If ip.AddressFamily.ToString() = "InterNetwork" Then Return ip.ToString()
Next
Return ipHost.AddressList(0).ToString()
Catch ex As Exception
Return String.Empty
End Try
End Function
End Class