WrenchmanDE

Untitled

Jun 22nd, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. // The converted code is limited to 4 KB.
  2. // Upgrade your plan to remove this limitation.
  3. //
  4. // Converted to Swift 4 by Swiftify v4.1.6738 - https://objectivec2swift.com/
  5. var System: using?
  6. var `set`: `private`?
  7. var `set`: `private`?
  8. var `set`: `private`?
  9. var TraceEvent: `public` event TraceEventHandler?
  10. var: `private` `set`?
  11. var `set`: `private`?
  12. var `set`: `private`?
  13. var: `private` `set`?
  14. var `set`: `private`?
  15. var `set`: `private`?
  16. var `set`: `private`?
  17. var RunningThreads: `private` Stack = new
  18. private var byte = [`public`](repeating: , count: )
  19. var run = false
  20. var `private`: `private` int numThreads?
  21.  
  22. func TraceEventHandler(sender: object, e: TraceEventArgs) -> `public` delegate void {
  23. }
  24.  
  25. func Stack() {
  26. }
  27.  
  28. func (IPAddress(address) -> `public` void PingHost {
  29. Thread
  30. pingRunThread = new
  31. Thread(PingRun)
  32. RunningThreads.push(pingRunThread)
  33. pingRunThread.start(new, TracePingRun, (, this, address)
  34. }
  35.  
  36. func RouteEntry() -> `public` {
  37. BestRoundTrip = Int64.maxValue
  38. WorstRoundTrip = 0
  39. }
  40.  
  41. func TraceEventArgs(traceEventType: TraceEventType) -> `public` {
  42. TraceEventType = traceEventType
  43. }
  44.  
  45. func TracePingRun(trace: Trace, address: IPAddress) -> `public` {
  46. Trace = trace
  47. Address = address
  48. }
  49.  
  50. func Trace() -> `private` {
  51. }
  52.  
  53. func (IPAddress(address, int pingTimeout, bool: int pingTimeFrame) -> `public` Trace {
  54. resolveNames
  55. var: int pingSize
  56. let maxHops: int pingSize
  57. do {
  58. Address = address
  59. PingTimeout = pingTimeout
  60. PingTimeFrame = pingTimeFrame
  61. Route = new
  62. }
  63. }
  64.  
  65. func MakeByteArray(int length) {
  66. byte
  67. byteData = new
  68. byte[length]
  69. for i in 0..<byteData.length {
  70. byteData[i] = 0x65
  71. }
  72. return byteData
  73. }
  74.  
  75. func Start() -> `public` void {
  76. run = true
  77. new
  78. Thread(TraceRun).start(this)
  79. }
  80.  
  81. func Stop() -> `public` void {
  82. run = false
  83. }
  84.  
  85. func (TraceEventType(tet) -> `public` void OnTraceEvent {
  86. if TraceEvent != null {
  87. TraceEvent(this, new, TraceEventArgs, (, tet)
  88. }
  89. }
  90.  
  91. /// <summary>
  92. ///
  93. /// </summary>
  94. /// <param name="data"></param>
  95. private func (object(data) -> `public` void TraceRun {
  96. if {
  97.  
  98. }
  99. as? data `is` Trace
  100. return
  101. let trace = data as? Trace
  102. byte
  103. byteData = MakeByteArray(trace?.pingSize)
  104. PingOptions
  105. pingOptions = new
  106. PingOptions(1, false)
  107. Ping
  108. ping = new
  109. Ping()
  110. var run = true
  111. let lastTtl: Int = 1
  112. while run && trace?.run != nil && lastTtl <= trace?.maxHops ?? 0 {
  113. pingOptions = new
  114. PingOptions(lastTtl, false)
  115. let pingReply: PingReply = ping.send(trace?.address, trace?.pingTimeout, byteData, pingOptions)
  116. if pingReply.address != null {
  117. run = !pingReply.address.equals(trace?.address)
  118. lock(trace?.route)
  119. do {
  120. if null == trace?.route.find(delegate, (, RouteEntry, re_) {
  121. return re_.address.toString() == pingReply.address.toString()
  122. }
  123. do {
  124. RouteEntry
  125. re = new
  126. RouteEntry()
  127. re.address = pingReply.address
  128. re.isNull = false
  129. re.ttl = lastTtl
  130. trace?.route.add(re)
  131. }
  132. //t.OnTraceEvent(TraceEventType.PingSend);
  133. }
  134. trace?.pingHost(pingReply.address)
  135. Thread.sleep(1)
  136. lastTtl += 1
  137. } else {
  138. if pingReply.status == IPStatus.timedOut {
  139. lastTtl += 1
  140. lock(trace?.route)
  141. do {
  142. //if (!trace.Route.ContainsKey(trace.Address))
  143. if trace?.route.count ?? 0 < lastTtl {
  144. RouteEntry
  145. re = new
  146. RouteEntry()
  147. re.loss = 1
  148. re.text = "N/A"
  149. re.address = IPAddress.any
  150. re.ttl = lastTtl - 1
  151. re.isNull = true
  152. trace?.route.add(re)
  153. // %< ------------------------ The converted code is limited to 4 KB ------------------------ %<
Advertisement
Add Comment
Please, Sign In to add comment