vb.net外网ip vbnet http服务器( 二 )


Exit Function
End If
RtlMoveMemory host, hostent_addr, LenB(host)
RtlMoveMemory hostip_addr, host.hAddrList, 4
ReDim temp_ip_address(1 To host.hLength)
RtlMoveMemory temp_ip_address(1), hostip_addr, host.hLength
For i = 1 To host.hLength
ip_address = ip_addresstemp_ip_address(i)"."
Next
ip_address = Mid$(ip_address, 1, Len(ip_address) - 1)
getip = ip_address
End Function
Private Sub Command1_click()
Dim str As String
str = getip(Text1.Text)
If str = "" Then
Text2.Text = "主机名不能被解释"
Else
Text2.Text = str
End If
End Sub
Private Function getname(addrstr As String) As String
Dim hostent_addr As Long
Dim host As HOSTENT
Dim addr(0 To 50) As Byte
Dim addrs As String
Dim hname(1 To 50) As Byte
Dim str As String
Dim i As Integer, j As Integer
Dim temp_int As Integer
Dim byt As Byte
str = Trim$(addrstr)
i = 0
j = 0
Do
temp_int = 0
i = i + 1
Do While Mid$(str, i, 1) = "0" And Mid$(str, i, 1) = "9" And i = Len(str)
temp_int = temp_int * 10 + Mid$(str, i, 1)
i = i + 1
Loop
If temp_int = 255 Then
addr(j) = temp_int
j = j + 1
End If
Loop Until Mid$(str, i, 1)"." Or iLen(str) Or temp_int255
If temp_int255 Then
getname = "地址非法"
Exit Function
End If
hostent_addr = gethostbyaddr(addr(0), j, 2)
If hostent_addr = 0 Then
getname = "此地址无法解析"
Exit Function
End If
RtlMoveMemory host, hostent_addr, LenB(host)
RtlMoveMemory hname(1), host.hname, 50
j = 51
For i = 1 To 50
If hname(i) = 0 Then
j = i
End If
If i = j Then
hname(i) = 32
End If
Next i
getname = Trim$(StrConv(hname, vbUnicode))
End Function
Private Sub Command2_Click()
Dim name As String
name = getname(Text2.Text)
If name = "" Then
name = "此地址没有域名"
End If
Text1.Text = name
End Sub
如何查看(或用VB.NET之类的程序)电脑的公网IP如果你是拨号连接,你就直接在宽带连接的详细信息里面看,那就有 , 要是通过家用路由器上网 , 就登录路由器,在状态里面也可以看到的
vb 如何获取外网ipvb 如何获取外网ip代码:
'获取公网IP
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" ( _
ByVal sAgent As String, ByVal lAccessType As Long, _
ByVal sProxyName As String, ByVal sProxyBypass As String, _
ByVal lFlags As Long) As Long
Private Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" ( _
ByVal hInternetSession As Long, ByVal sUrl As String, _
ByVal sHeaders As String, ByVal lHeadersLength As Long, _
ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function InternetReadFile Lib "wininet.dll" ( _
ByVal hFile As Long, ByVal sBuffer As String, _
ByVal lNumBytesToRead As Long, _
lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetCloseHandle Lib "wininet.dll" ( _
ByVal hInet As Long) As Integer
Private Const INTERNET_FLAG_NO_CACHE_WRITE = H4000000
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Function GetSub() As String
Dim wburl$, wburl2$, X1, X2, X3, X4
On Error GoTo err
wburl = ""
wburl = GetUrlFile(wburl)
If InStr(1, wburl, "无法找到该页") = 0 Then
X1 = InStr(1, wburl, "[")
X2 = InStr(1, wburl, "]")
X1 = Mid(wburl, X1, X2 - X1)
X1 = Replace(X1, "[", "")
X1 = Replace(X1, " ", "")

推荐阅读