VB 将域名转换成IP地址_VB.net_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

VB 将域名转换成IP地址

作者:黑客防线网安VB教程基地 来源:黑客防线网安VB教程基地 浏览次数:0

本篇关键词:地址转换域名 
黑客防线网安网讯:Option ExplicitPrivate Type HOSTENThName As LonghAliases As LonghAddrType As IntegerhLength As IntegerhAddrList As LongEnd TypePrivate Type WSADATAwversion As IntegerwHighVersi...

Option Explicit

Private Type HOSTENT
hName As Long
hAliases As Long
hAddrType As Integer
hLength As Integer
hAddrList As Long
End Type

Private Type WSADATA
wversion As Integer
wHighVersion As Integer
szDescription(0 To 256) As Byte
szSystemStatus(0 To 128) As Byte
iMaxSockets As Integer
iMaxUdpDg As Integer
lpszVendorInfo As Long
End Type

Private Declare Function WSAGetLastError Lib "WSOCK32.DLL" () As Long
Private Declare Function WSAStartup Lib "WSOCK32.DLL" (ByVal wVersionRequired As Integer, lpWSAData As WSADATA) As Long
Private Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long
Private Declare Function gethostname Lib "WSOCK32.DLL" (ByVal szHostname As String, ByVal HostLen As Long) As Long
Private Declare Function gethostbyname Lib "WSOCK32.DLL" (ByVal szHostname As String) As Long
Private Declare Sub RtlMoveMemory Lib "KERNEL32" (hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)

Private Const WS_VERSION_REQD = &H101

Private Function Test(URL As String) As String
InitializeWinSock
Test = GetAddressByName(URL)
TerminateWinSock
End Function

Private Function GetAddressByName(strHostname As String)
Dim lngAddr As Long
Dim udtHost As HOSTENT
Dim lngIP As Long
Dim bteTmp() As Byte
Dim i As Integer
Dim strIP As String

lngAddr = gethostbyname(strHostname)

If lngAddr = 0 Then
    MsgBox "Kein Host gefunden."
    GetAddressByName = Null
    Exit Function
End If

RtlMoveMemory udtHost, lngAddr, LenB(udtHost)
RtlMoveMemory lngIP, udtHost.hAddrList, 4

ReDim bteTmp(1 To udtHost.hLength)
RtlMoveMemory bteTmp(1), lngIP, udtHost.hLength
For i = 1 To udtHost.hLength
    strIP = strIP & bteTmp(i) & "."
Next
strIP = Mid$(strIP, 1, Len(strIP) - 1)

GetAddressByName = strIP

End Function

Private Sub InitializeWinSock()
Dim udtWSAD As WSADATA
Dim lngRet As Long
lngRet = WSAStartup(WS_VERSION_REQD, udtWSAD)
If lngRet <> 0 Then
    MsgBox "Winsock.dll konnte nicht initialisiert werden."
End
End If
End Sub

Private Sub TerminateWinSock()
Dim lngRet As Long
lngRet = WSACleanup()
If lngRet <> 0 Then
    MsgBox "Fehler " & lngRet & " beim Beenden von Winsock.dll"
End
End If
End Sub

Private Sub Command1_Click()
Dim MyURL As String
MyURL = "MsgBox MyURL & "的IP地址是:" & Test(MyURL)
End Sub

    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-14687-1.html
网站维护教程更新时间:2012-04-03 01:12:29  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer