for i = 1 to host.hlength
ip_address = ip_address & temp_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 i > len(str) or temp_int > 255
if temp_int > 255 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