Posts: 14
Threads: 6
Joined: Jul 2006
Hi, I am looking for a function that can return the ping in milliseconds. I have made one using windows ping command through a .bat file, but that really wastes time having to run bat file, output to text file and then .getfile in QM. Is there another way to make a function that returns the ping? Thanks in advance.
Posts: 12,072
Threads: 140
Joined: Dec 2002
Wsh.WshShell objShell._create
Wsh.WshExec objScriptExec = objShell.Exec("ping -n 3 -w 1000 www.quickmacros.com")
str s=objScriptExec.StdOut.ReadAll
s.replacerx("[[]]+" "[]")
mes s
To get just time, use IntPing
long t1=perf
if(!IntPing("http://www.quickmacros.com")) end "no response"
long t2=perf
int i=t2-t1/1000
out i
Posts: 12,072
Threads: 140
Joined: Dec 2002
Function IntPing2
function# [$url]
;Attempts to connect to url.
;If successful, returns the time (ms) spent to connect. If cannot connect, returns 0.
long t1=perf
if(!inet.InternetCheckConnection(url inet.FLAG_ICC_FORCE_CONNECTION 0)) ret
long t2=perf
int i=t2-t1/1000
if(!i) i=1
ret i
Example
out IntPing2("http://www.quickmacros.com")
Posts: 1,769
Threads: 410
Joined: Feb 2003
Posts: 14
Threads: 6
Joined: Jul 2006
HAHA I LOVE IT!!! Thank you. This is the best piece of software I have ever owned. Well the first that I ever owned. Worth every penny. Thanks.
Posts: 14
Threads: 6
Joined: Jul 2006
Interesting...I really like the first solution. I can use that for other window commands too, but the second solution is even better. simple and easier to implement. Thanks.
Posts: 1,769
Threads: 410
Joined: Feb 2003
Yeah. you know i just went through a tonne of old 3.5 disks the other night. and threw away hundreds of dollars of software i bought and havent used in 10 years or MORE!
thus my opinion is that you dont buy software you lease it. But this one is definitely worth the $40!
Posts: 858
Threads: 196
Joined: Apr 2005
How can I ping to ip direction?
example: IntPing2("10.3.6.32")
Posts: 1,271
Threads: 399
Joined: Mar 2003
Lucas Wrote:How can I ping to ip direction?
example: IntPing2("10.3.6.32")
You found a solution?
Posts: 1,271
Threads: 399
Joined: Mar 2003
I think this one is good, but need help with translating for qm
https://stackoverflow.com/questions/306 ... p-and-port
This snippet will work for testing a server listening to a given IP and port with the TCP protocol.
Futhermore, you could also try to ping the IP:
Ping ping = new Ping();
PingReply pingReply = ping.Send("192.168.0.200");
if (pingReply.Status == IPStatus.Success)
{
//Server is alive
}
Ping class is located in System.Net.NetworkInformation.
Posts: 12,072
Threads: 140
Joined: Dec 2002
I guess, the .NET Ping does the same as the Ping function in Archive.qml.
Collected QM apps, functions, samples
Posts: 1,271
Threads: 399
Joined: Mar 2003
I am sorry, but which function is it there?
What i need i a simple solution to check if my given IP is online or not.
Posts: 12,072
Threads: 140
Joined: Dec 2002
It is function named Ping.
C# version
Macro Scripting C#, call single static function2
str R=CsFunc("" "www.example.com")
out R ;;0 is Success
#ret
//C# code
using System;
using System.Net.NetworkInformation;
public class Test
{
public static IPStatus Ping2(string s)
{
try {
;Ping ping = new Ping();
;PingReply pingReply = ping.Send(s);
;return pingReply.Status;
}
catch(Exception ex) { Console.WriteLine(ex.Message); return IPStatus.Unknown; }
}
}
/*
,public enum IPStatus
,{
,,//
,,// Summary:
,,// The ICMP echo request failed for an unknown reason.
,,Unknown = -1,
,,//
,,// Summary:
,,// The ICMP echo request succeeded; an ICMP echo reply was received. When you get
,,// this status code, the other System.Net.NetworkInformation.PingReply properties
,,// contain valid data.
,,Success = 0,
,,//
,,// Summary:
,,// The ICMP echo request failed because the network that contains the destination
,,// computer is not reachable.
,,DestinationNetworkUnreachable = 11002,
,,//
,,// Summary:
,,// The ICMP echo request failed because the destination computer is not reachable.
,,DestinationHostUnreachable = 11003,
,,//
,,// Summary:
,,// The ICMP echo request failed because the destination computer that is specified
,,// in an ICMP echo message is not reachable, because it does not support the packet's
,,// protocol. This value applies only to IPv4. This value is described in IETF RFC
,,// 1812 as Communication Administratively Prohibited.
,,DestinationProtocolUnreachable = 11004,
,,//
,,// Summary:
,,// The ICMPv6 echo request failed because contact with the destination computer
,,// is administratively prohibited. This value applies only to IPv6.
,,DestinationProhibited = 11004,
,,//
,,// Summary:
,,// The ICMP echo request failed because the port on the destination computer is
,,// not available.
,,DestinationPortUnreachable = 11005,
,,//
,,// Summary:
,,// The ICMP echo request failed because of insufficient network resources.
,,NoResources = 11006,
,,//
,,// Summary:
,,// The ICMP echo request failed because it contains an invalid option.
,,BadOption = 11007,
,,//
,,// Summary:
,,// The ICMP echo request failed because of a hardware error.
,,HardwareError = 11008,
,,//
,,// Summary:
,,// The ICMP echo request failed because the packet containing the request is larger
,,// than the maximum transmission unit (MTU) of a node (router or gateway) located
,,// between the source and destination. The MTU defines the maximum size of a transmittable
,,// packet.
,,PacketTooBig = 11009,
,,//
,,// Summary:
,,// The ICMP echo Reply was not received within the allotted time. The default time
,,// allowed for replies is 5 seconds. You can change this value using the Overload:System.Net.NetworkInformation.Ping.Send
,,// or Overload:System.Net.NetworkInformation.Ping.SendAsync methods that take a
,,// timeout parameter.
,,TimedOut = 11010,
,,//
,,// Summary:
,,// The ICMP echo request failed because there is no valid route between the source
,,// and destination computers.
,,BadRoute = 11012,
,,//
,,// Summary:
,,// The ICMP echo request failed because its Time to Live (TTL) value reached zero,
,,// causing the forwarding node (router or gateway) to discard the packet.
,,TtlExpired = 11013,
,,//
,,// Summary:
,,// The ICMP echo request failed because the packet was divided into fragments for
,,// transmission and all of the fragments were not received within the time allotted
,,// for reassembly. RFC 2460 (available at www.ietf.org) specifies 60 seconds as
,,// the time limit within which all packet fragments must be received.
,,TtlReassemblyTimeExceeded = 11014,
,,//
,,// Summary:
,,// The ICMP echo request failed because a node (router or gateway) encountered problems
,,// while processing the packet header. This is the status if, for example, the header
,,// contains invalid field data or an unrecognized option.
,,ParameterProblem = 11015,
,,//
,,// Summary:
,,// The ICMP echo request failed because the packet was discarded. This occurs when
,,// the source computer's output queue has insufficient storage space, or when packets
,,// arrive at the destination too quickly to be processed.
,,SourceQuench = 11016,
,,//
,,// Summary:
,,// The ICMP echo request failed because the destination IP address cannot receive
,,// ICMP echo requests or should never appear in the destination address field of
,,// any IP datagram. For example, calling Overload:System.Net.NetworkInformation.Ping.Send
,,// and specifying IP address "000.0.0.0" returns this status.
,,BadDestination = 11018,
,,//
,,// Summary:
,,// The ICMP echo request failed because the destination computer that is specified
,,// in an ICMP echo message is not reachable; the exact cause of problem is unknown.
,,DestinationUnreachable = 11040,
,,//
,,// Summary:
,,// The ICMP echo request failed because its Time to Live (TTL) value reached zero,
,,// causing the forwarding node (router or gateway) to discard the packet.
,,TimeExceeded = 11041,
,,//
,,// Summary:
,,// The ICMP echo request failed because the header is invalid.
,,BadHeader = 11042,
,,//
,,// Summary:
,,// The ICMP echo request failed because the Next Header field does not contain a
,,// recognized value. The Next Header field indicates the extension header type (if
,,// present) or the protocol above the IP layer, for example, TCP or UDP.
,,UnrecognizedNextHeader = 11043,
,,//
,,// Summary:
,,// The ICMP echo request failed because of an ICMP protocol error.
,,IcmpError = 11044,
,,//
,,// Summary:
,,// The ICMP echo request failed because the source address and destination address
,,// that are specified in an ICMP echo message are not in the same scope. This is
,,// typically caused by a router forwarding a packet using an interface that is outside
,,// the scope of the source address. Address scopes (link-local, site-local, and
,,// global scope) determine where on the network an address is valid.
,,DestinationScopeMismatch = 11045
,}
*/
Posts: 1,271
Threads: 399
Joined: Mar 2003
I don't get how to use IP Adress instead of "www.example.com"
Just simple checking if IP example 192.168.20.40 is online or not.
Posts: 12,072
Threads: 140
Joined: Dec 2002
For "192.168.20.40" returns error code 11013, but for http://www.example.com IP "93.184.216.34" returns 0.
Posts: 1,271
Threads: 399
Joined: Mar 2003
Sorry.
Zero is success i had not on mind.
out R ;;0 is Success
Thanks G.
|