a program that i altered from Paul Dwyer's ping program.
i removed some code and added very little so any credit should be sent Paul Dwyer's way.
the purpose of the program is ping a site and return an errlevel for batch programs. i use this program inside a batch fille that is run every time my computer is booted up and it does very well for laptop computers.
i will list the batch file that i have created and i wrote a program i name sleep.exe to put some sleep states in the batch file.
this program is very helpful if your internet service is down a lot or your testing when your internet service starts back up. simply by placing a beep or song or some weird graphic display in the batch file.
my program, sleep, should be listed somewhere here on in the source code section.
my program ,sleepbrk, does is almost the same program as sleep except it allows you to break the sleepbrk program by hitting a key.
both the batch file and two programs can be download from http://pdptemp.dyndns.org/zipcode for a short time from this date.
the batch file i use
i removed some code and added very little so any credit should be sent Paul Dwyer's way.
the purpose of the program is ping a site and return an errlevel for batch programs. i use this program inside a batch fille that is run every time my computer is booted up and it does very well for laptop computers.
i will list the batch file that i have created and i wrote a program i name sleep.exe to put some sleep states in the batch file.
this program is very helpful if your internet service is down a lot or your testing when your internet service starts back up. simply by placing a beep or song or some weird graphic display in the batch file.
my program, sleep, should be listed somewhere here on in the source code section.
my program ,sleepbrk, does is almost the same program as sleep except it allows you to break the sleepbrk program by hitting a key.
both the batch file and two programs can be download from http://pdptemp.dyndns.org/zipcode for a short time from this date.
Code:
'compiled with pbcc 4.03 'pingstrt.bas #COMPILE EXE #INCLUDE "WIN32API.INC" %IP_SUCCESS = 0 %IP_STATUS_BASE = 11000 %IP_BUF_TOO_SMALL = (11000 + 1) %IP_DEST_NET_UNREACHABLE = (11000 + 2) %IP_DEST_HOST_UNREACHABLE = (11000 + 3) %IP_DEST_PROT_UNREACHABLE = (11000 + 4) %IP_DEST_PORT_UNREACHABLE = (11000 + 5) %IP_NO_RESOURCES = (11000 + 6) %IP_BAD_OPTION = (11000 + 7) %IP_HW_ERROR = (11000 + 8) %IP_PACKET_TOO_BIG = (11000 + 9) %IP_REQ_TIMED_OUT = (11000 + 10) %IP_BAD_REQ = (11000 + 11) %IP_BAD_ROUTE = (11000 + 12) %IP_TTL_EXPIRED_TRANSIT = (11000 + 13) %IP_TTL_EXPIRED_REASSEM = (11000 + 14) %IP_PARAM_PROBLEM = (11000 + 15) %IP_SOURCE_QUENCH = (11000 + 16) %IP_OPTION_TOO_BIG = (11000 + 17) %IP_BAD_DESTINATION = (11000 + 18) %IP_ADDR_DELETED = (11000 + 19) %IP_SPEC_MTU_CHANGE = (11000 + 20) %IP_MTU_CHANGE = (11000 + 21) %IP_UNLOAD = (11000 + 22) %IP_ADDR_ADDED = (11000 + 23) %IP_GENERAL_FAILURE = (11000 + 50) %MAX_IP_STATUS = (11000 + 50) %IP_PENDING = (11000 + 255) %PING_TIMEOUT = 3000 %WS_VERSION_REQD = &H101 %MIN_SOCKETS_REQD = 1 %SOCKET_ERROR = -1 %INADDR_NONE = &HFFFFFFFF %MAX_WSADescription = 256 %MAX_WSASYSStatus = 128 TYPE ICMP_OPTIONS Ttl AS BYTE Tos AS BYTE Flags AS BYTE OptionsSize AS BYTE OptionsData AS LONG END TYPE TYPE ICMP_ECHO_REPLY Address AS LONG lStatus AS LONG RoundTripTime AS LONG DataSize AS LONG 'formerly integer 'Reserved As Integer DataPointer AS LONG Options AS ICMP_OPTIONS sData AS STRING * 250 END TYPE TYPE RTT 'Round Trip Time info RTT AS LONG ErrorCode AS LONG ErrorText AS STRING * 24 END TYPE DECLARE FUNCTION inet_addr LIB "wsock32.dll" ALIAS "inet_addr" (BYVAL s AS STRING) AS LONG DECLARE FUNCTION GetStatusCode(STATUS AS LONG) AS STRING DECLARE SUB ping(sHost AS STRING, lTimeOutMs AS LONG, payload AS STRING, oRTT AS RTT) DECLARE FUNCTION ResolveHost(sHost AS STRING) AS STRING DECLARE FUNCTION IcmpCreateFile LIB "icmp.dll" ALIAS "IcmpCreateFile" () AS LONG DECLARE FUNCTION IcmpCloseHandle LIB "icmp.dll" ALIAS "IcmpCloseHandle"(BYVAL IcmpHandle AS LONG) AS LONG DECLARE FUNCTION IcmpSendEcho LIB "icmp.dll" ALIAS "IcmpSendEcho" _ (BYVAL IcmpHandle AS LONG, _ BYVAL DestinationAddress AS LONG, _ BYVAL RequestData AS STRING, _ BYVAL RequestSize AS LONG, _ BYVAL RequestOptions AS LONG, _ ReplyBuffer AS ICMP_ECHO_REPLY, _ BYVAL ReplySize AS LONG, BYVAL lTimeout AS LONG) AS LONG '=================================================================== FUNCTION GetStatusCode(STATUS AS LONG) AS STRING DIM msg AS STRING SELECT CASE STATUS CASE %IP_SUCCESS: msg = "Success" CASE %INADDR_NONE: msg = "Bad IP format" CASE %IP_BUF_TOO_SMALL: msg = "Buffer too small" CASE %IP_DEST_NET_UNREACHABLE: msg = "Dest net unreachable" CASE %IP_DEST_HOST_UNREACHABLE: msg = "Dest host unreachable" CASE %IP_DEST_PROT_UNREACHABLE: msg = "Dest prot unreachable" CASE %IP_DEST_PORT_UNREACHABLE: msg = "Dest port unreachable" CASE %IP_NO_RESOURCES: msg = "No resources" CASE %IP_BAD_OPTION: msg = "Bad option" CASE %IP_HW_ERROR: msg = "HW Error" CASE %IP_PACKET_TOO_BIG: msg = "Packet too big" CASE %IP_REQ_TIMED_OUT: msg = "Req timed out" CASE %IP_BAD_REQ: msg = "Bad req" CASE %IP_BAD_ROUTE: msg = "Bad route" CASE %IP_TTL_EXPIRED_TRANSIT: msg = "TTL expired transit" CASE %IP_TTL_EXPIRED_REASSEM: msg = "TTL expired reassem" CASE %IP_PARAM_PROBLEM: msg = "Param problem" CASE %IP_SOURCE_QUENCH: msg = "Source quench" CASE %IP_OPTION_TOO_BIG: msg = "Option too big" CASE %IP_BAD_DESTINATION: msg = "Bad destination" CASE %IP_ADDR_DELETED: msg = "Addr deleted" CASE %IP_SPEC_MTU_CHANGE: msg = "Spec MTU change" CASE %IP_MTU_CHANGE: msg = "MTU change" CASE %IP_UNLOAD: msg = "Unload" CASE %IP_ADDR_ADDED: msg = "Addr added" CASE %IP_GENERAL_FAILURE: msg = "General failure" CASE %IP_PENDING: msg = "Pending" CASE %PING_TIMEOUT: msg = "Ping timeout" CASE ELSE: msg = "Unknown Err " & FORMAT$(STATUS) END SELECT GetStatusCode = msg END FUNCTION '=================================================================== SUB ping(sHost AS STRING, lTimeOutMs AS LONG, payload AS STRING, oRTT AS RTT) DIM hPort AS LONG DIM dwAddress AS LONG DIM ECHO AS ICMP_ECHO_REPLY DIM pOptions AS LONG DIM ResolvedHost AS STRING 'convert the address into a long representation dwAddress = inet_addr(sHost) IF dwAddress = -1 THEN 'Might be a host name, try to resolve first. ResolvedHost = ResolveHost(sHost) dwAddress = inet_addr(ResolvedHost) IF dwAddress = -1 THEN 'If still bad then fail oRTT.ErrorCode = -1 oRTT.ErrorText = "DNS Resolution Failure" EXIT SUB END IF END IF 'open a port hPort = IcmpCreateFile() IF hPort THEN 'ping it. CALL IcmpSendEcho(hPort, dwAddress, payload, LEN(payload), pOptions, ECHO, LEN(ECHO), lTimeOutMs) 'return the status as ping succes and close oRTT.ErrorCode = ECHO.lstatus oRTT.ErrorText = GetStatusCode(ECHO.lstatus) oRTT.RTT = ECHO.RoundTripTime CALL IcmpCloseHandle(hPort) END IF END SUB '================================================================================ FUNCTION ResolveHost(sHost AS STRING) AS STRING DIM p AS BYTE PTR DIM IP AS DWORD HOST ADDR sHost TO IP p = VARPTR(IP) ResolveHost = USING$("#_.#_.#_.#", @p, @p[1], @p[2], @p[3]) END FUNCTION '=================================================================== FUNCTION PBMAIN() AS LONG DIM sHost AS STRING DIM TimeOutSecs AS LONG DIM Payload AS STRING DIM RoundTripInfo AS RTT sHost = trim$(COMMAND$) IF LEN(sHost)=0 THEN FUNCTION=2 STDOUT "ERRORLEVEL 2 returned" EXIT FUNCTION END IF TimeOutSecs = 2000 Payload = "abcdefghijklmnop" CALL ping(sHost, TimeOutSecs, Payload, RoundTripInfo) STDOUT "pinging " & sHost STDOUT "Status: " & FORMAT$(RoundTripInfo.ErrorCode) & " (" & TRIM$(RoundTripInfo.ErrorText) & ")" STDOUT "Time: " & FORMAT$(RoundTripInfo.RTT) & " ms" IF roundtripinfo.errorcode=0 THEN FUNCTION=0 STDOUT "ERRORLEVEL 0 returned" ELSE FUNCTION=1 STDOUT "ERRORLEVEL 1 returned" END IF END FUNCTION
Code:
rem ckinternet.bat echo off c: cd \wsbat :internet cls echo _ echo checking internet in 1 seconds echo _ sleep 1.25 echo checking for www.yahoo.com SLEEP 1 pingstrt www.yahoo.com IF ERRORLEVEL == 1 GOTO AROUND1 IF ERRORLEVEL == 0 goto endofcheck :AROUND1 echo _ echo _ checking for google.com SLEEP 1 pingstrt www.google.com IF ERRORLEVEL == 1 GOTO AROUND2 IF ERRORLEVEL == 0 goto endofcheck :AROUND2 SLEEP 1 goto internet :endofcheck exit
Comment