여러 사이트를 돌아다니면서 찾아보고 카페자료도 뒤져보고 정리를 했습니다.
윈도에서 제공하는 기본 API를 이용하였습니다.
작성 기준은 10.5 입니다.
// 선언
type hostent from structure
unsignedlong h_name
unsignedlong h_aliases
integer h_addrtype
integer h_length
unsignedlong h_addr_list
end type
type in_addr from structure
unsignedlong s_addr
end type
type str_icmp_options from structure
integer a_ttl
integer a_tos
integer a_flags
integer a_OptionsSize
long a_OptionsData
end type
type str_replybuffer from structure
long a_address
long a_status
long a_roundtriptime
long a_datasize
integer a_reserved
long a_datapointer
str_icmp_options str_icmp_options
string a_data
end type
//API 선언
Function ulong gethostbyname(string name ) Library "ws2_32.dll" alias for "gethostbyname;Ansi"
Subroutine CopyMemoryIP(Ref structure Destination, &
ulong Source, long Length ) Library "kernel32.dll" Alias For "RtlMoveMemory;Ansi"
Function integer WSAGetLastError() Library "ws2_32.dll"
Function long IcmpCreateFile () LIBRARY "icmp.dll"
Function long IcmpSendEcho(long IcmpHandle, long DestinationAddress, &
string RequestData, long RequestSize, long RequestOptions, &
ref str_replybuffer str_replybuffer, long ReplySize, &
long Timeout) LIBRARY "icmp.dll" Alias for "IcmpSendEcho;Ansi"
Function long inet_addr (string sIP4 ) LIBRARY "WSOCK32.DLL" Alias for "inet_addr;Ansi"
Function long IcmpCloseHandle (long IcmpHandle) LIBRARY "icmp.dll"
// URL -> IP4로 변경
// String f_GetIPAddress( string as_hostname )
String ls_ipaddress, ls_errmsg
HOSTENT lstr_host
ULong lul_ptr, lul_ipaddr
IN_ADDR lstr_addr
lul_ptr = gethostbyname(as_hostname)
If lul_ptr > 0 Then
CopyMemoryIP(lstr_host, lul_ptr, 16)
CopyMemoryIP(lul_ipaddr, lstr_host.h_addr_list, 4)
CopyMemoryIP(lstr_addr, lul_ipaddr, 4)
ls_ipaddress = String(Blob(inet_ntoa(lstr_addr.s_addr)))
Else
lul_ptr = WSAGetLastError()
End If
Return ls_ipaddress
// Ping 을 해봅시다.
// string f_ping( string as_url )
str_replybuffer str_replybuffer
string sDataToSend = "", ls_ip
long hPort, dwAddress, PING_TIMEOUT = 1000
ls_ip = in_WS.of_GetIPAddress( as_url )
hPort = IcmpCreateFile()
dwAddress = inet_addr(ls_ip)
IcmpSendEcho(hPort, dwAddress, sDataToSend, Len(sDataToSend), 0, str_replybuffer, 500, PING_TIMEOUT)
IcmpCloseHandle(hPort)
if str_replybuffer.a_status = 0 then
ls_ping = 'OK'
else
ls_ping = 'ERROR'
end if
return ls_ping