#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.5 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include-once #include Global $___Csharp_codestring="" Global $___ping_Instance global $___ping_Debug=False Global $___ping_intiated=false $___Csharp_codestring&= 'using System;'&@crlf $___Csharp_codestring&= 'using System.Text;'&@crlf $___Csharp_codestring&= 'using System.Net;'&@crlf $___Csharp_codestring&= 'using System.Net.NetworkInformation;'&@crlf $___Csharp_codestring&= 'using System.ComponentModel;'&@crlf $___Csharp_codestring&= 'using System.Threading;'&@crlf $___Csharp_codestring&= 'using System.Threading.Tasks;'&@crlf $___Csharp_codestring&= 'using System.Linq;'&@crlf $___Csharp_codestring&= ''&@crlf $___Csharp_codestring&= ''&@crlf $___Csharp_codestring&= 'class Dotnet_Class'&@crlf $___Csharp_codestring&= '{'&@crlf $___Csharp_codestring&= ' private long[] result;'&@crlf $___Csharp_codestring&= ' private ManualResetEvent[] tasks;'&@crlf $___Csharp_codestring&= ' public bool debug = false;'&@crlf $___Csharp_codestring&= ''&@crlf $___Csharp_codestring&= ' public long Ping_Host(string IP, int timeout, int size, int ttl, bool dontfragment) '&@crlf $___Csharp_codestring&= ' {'&@crlf $___Csharp_codestring&= ' long singleresult = -1;'&@crlf $___Csharp_codestring&= ' try'&@crlf $___Csharp_codestring&= ' {'&@crlf $___Csharp_codestring&= ' Ping pingpacket = new Ping();'&@crlf $___Csharp_codestring&= ' PingOptions option = new PingOptions(ttl, dontfragment);'&@crlf $___Csharp_codestring&= ' PingReply reply= pingpacket.Send(IP, timeout, createbuffer(size), option);'&@crlf $___Csharp_codestring&= ' if (reply.Status == IPStatus.Success)'&@crlf $___Csharp_codestring&= ' {'&@crlf $___Csharp_codestring&= ' if (reply.RoundtripTime == 0)'&@crlf $___Csharp_codestring&= ' {'&@crlf $___Csharp_codestring&= ' singleresult = 1;'&@crlf $___Csharp_codestring&= ' }'&@crlf $___Csharp_codestring&= ' else'&@crlf $___Csharp_codestring&= ' {'&@crlf $___Csharp_codestring&= ' singleresult = reply.RoundtripTime;'&@crlf $___Csharp_codestring&= ' }'&@crlf $___Csharp_codestring&= ' }'&@crlf $___Csharp_codestring&= ' else'&@crlf $___Csharp_codestring&= ' {'&@crlf $___Csharp_codestring&= ' singleresult = 0;'&@crlf $___Csharp_codestring&= ' }'&@crlf $___Csharp_codestring&= ' }'&@crlf $___Csharp_codestring&= ' catch (Exception e)'&@crlf $___Csharp_codestring&= ' {'&@crlf $___Csharp_codestring&= ' if (debug) { Console.WriteLine(e.ToString()); }'&@crlf $___Csharp_codestring&= ' }'&@crlf $___Csharp_codestring&= ' return singleresult;'&@crlf $___Csharp_codestring&= ' }'&@crlf $___Csharp_codestring&= ' public long[] Ping_Array(object[] IPS, int timeout, int size, int ttl, bool dontfragment)'&@crlf $___Csharp_codestring&= ' {'&@crlf $___Csharp_codestring&= ' try'&@crlf $___Csharp_codestring&= ' {'&@crlf $___Csharp_codestring&= ' tasks = new ManualResetEvent[IPS.Length];'&@crlf $___Csharp_codestring&= ' result = new long[IPS.Length];'&@crlf $___Csharp_codestring&= ' for (int i = 0; i < IPS.Length; i++)'&@crlf $___Csharp_codestring&= ' {'&@crlf $___Csharp_codestring&= ' Ping pingpacket = new Ping();'&@crlf $___Csharp_codestring&= ' PingOptions option = new PingOptions(ttl, dontfragment);'&@crlf $___Csharp_codestring&= ' pingpacket.PingCompleted += new PingCompletedEventHandler(pingcallback);'&@crlf $___Csharp_codestring&= ' pingpacket.SendAsync((string)IPS[i], timeout, createbuffer(size), i);'&@crlf $___Csharp_codestring&= ' tasks[i] = new ManualResetEvent(false);'&@crlf $___Csharp_codestring&= ' }'&@crlf $___Csharp_codestring&= ' foreach (ManualResetEvent task in tasks)'&@crlf $___Csharp_codestring&= ' {'&@crlf $___Csharp_codestring&= ' task.WaitOne();'&@crlf $___Csharp_codestring&= ' }'&@crlf $___Csharp_codestring&= ' tasks = null;'&@crlf $___Csharp_codestring&= ' }'&@crlf $___Csharp_codestring&= ' catch (Exception e)'&@crlf $___Csharp_codestring&= ' {'&@crlf $___Csharp_codestring&= ' for (int i = 0; i < IPS.Length; i++)'&@crlf $___Csharp_codestring&= ' {'&@crlf $___Csharp_codestring&= ' result[i] = -1;'&@crlf $___Csharp_codestring&= ' }'&@crlf $___Csharp_codestring&= ' if (debug) { Console.WriteLine(e.ToString()); }'&@crlf $___Csharp_codestring&= ' }'&@crlf $___Csharp_codestring&= ' return result;'&@crlf $___Csharp_codestring&= ' }'&@crlf $___Csharp_codestring&= ''&@crlf $___Csharp_codestring&= ' private void pingcallback(object obj, PingCompletedEventArgs e)'&@crlf $___Csharp_codestring&= ' {'&@crlf $___Csharp_codestring&= ' int i = (int)e.UserState;'&@crlf $___Csharp_codestring&= ' if (e.Error != null)'&@crlf $___Csharp_codestring&= ' {'&@crlf $___Csharp_codestring&= ' result[i] = -1;'&@crlf $___Csharp_codestring&= ' }'&@crlf $___Csharp_codestring&= ' else if (e.Reply.Status == IPStatus.Success)'&@crlf $___Csharp_codestring&= ' {'&@crlf $___Csharp_codestring&= ' if (e.Reply.RoundtripTime == 0)'&@crlf $___Csharp_codestring&= ' {'&@crlf $___Csharp_codestring&= ' result[i] = 1;'&@crlf $___Csharp_codestring&= ' }'&@crlf $___Csharp_codestring&= ' else'&@crlf $___Csharp_codestring&= ' {'&@crlf $___Csharp_codestring&= ' result[i] = e.Reply.RoundtripTime;'&@crlf $___Csharp_codestring&= ' }'&@crlf $___Csharp_codestring&= ' }'&@crlf $___Csharp_codestring&= ' else'&@crlf $___Csharp_codestring&= ' {'&@crlf $___Csharp_codestring&= ' result[i] = 0;'&@crlf $___Csharp_codestring&= ' }'&@crlf $___Csharp_codestring&= ' tasks[i].Set();'&@crlf $___Csharp_codestring&= ' }'&@crlf $___Csharp_codestring&= ' private byte[] createbuffer(int size)'&@crlf $___Csharp_codestring&= ' {'&@crlf $___Csharp_codestring&= ' byte[] buffer = new byte[size];'&@crlf $___Csharp_codestring&= ' Random rng = new Random();'&@crlf $___Csharp_codestring&= ' rng.NextBytes(buffer);'&@crlf $___Csharp_codestring&= ' return buffer;'&@crlf $___Csharp_codestring&= ' }'&@crlf $___Csharp_codestring&= ' '&@crlf $___Csharp_codestring&= '}'&@crlf $___Csharp_codestring&= ''&@crlf Func __ping_Intiate() $code=DotNet_LoadCScode($___Csharp_codestring,"System.dll | System.Core.dll |System.Net.dll |System.Net.NetworkInformation.dll |System.Threading.dll | mscorlib.dll| System.Runtime.dll") if Not IsObj($code) and $___ping_Debug then return ConsoleWrite("_ping Err : Dotnet Code Not Loaded!!!!!!"&@crlf) $___ping_Instance=DotNet_CreateObject($code,"Dotnet_Class") if Not IsObj($___ping_Instance) and $___ping_Debug then return ConsoleWrite("_ping Err : Instance Err!!!!!!"&@crlf) $___ping_intiated=true EndFunc Func _ping($ip,$timeout=4000,$TTL=255,$DontFragment=False,$BufferSize=32) $err=not (IsInt($timeout) and IsInt($BufferSize) and IsInt($TTL) and IsBool($DontFragment)) if IsBool($DontFragment) then $DontFragment=False if not $___ping_intiated then __ping_Intiate() $result=-1 if not IsArray($ip) Then $result=$___ping_Instance.Ping_Host($ip,$timeout,$BufferSize,$TTL,$DontFragment) Else $result=$___ping_Instance.Ping_Array($ip,$timeout,$BufferSize,$TTL,$DontFragment) EndIf Return $result EndFunc Func _ping_debug($bool) if IsBool($bool) then if not $___ping_intiated then __ping_Intiate() $___ping_Debug=$bool $___ping_Instance.debug=$bool EndIf endfunc