Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

resolves #23 added a traceRouteWithPort option #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany</groupId>
<groupId>com.mulesoft.tool</groupId>
<artifactId>net-tools-api</artifactId>
<version>2.4.0</version>
<version>2.4.0-issue23-SNAPSHOT</version>
<packaging>mule-application</packaging>

<name>net-tools-api</name>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/mulesoft/tool/network/NetworkUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public static String traceRoute(String host) throws Exception {
return execute(new ProcessBuilder("traceroute", "-w", "3", "-q", "1", "-m", "18", "-n", host));
}

public static String traceRouteWithPort(String host, String port) throws Exception {
return execute(new ProcessBuilder("traceroute", "-w", "3", "-q", "1", "-m", "18", "-p", port, "-n", host));
}

public static String certest(String host, String port) throws Exception {
return execute(new ProcessBuilder("openssl", "s_client", "-showcerts", "-servername", host, "-connect", host+":"+port));
}
Expand Down
33 changes: 21 additions & 12 deletions src/main/mule/net-tools.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ splitBy(attributes.requestPath, ".")[-1] default ""]]></ee:set-variable>
<apikit:router config-ref="net-tools-config" />
<error-handler>
<on-error-propagate type="APIKIT:BAD_REQUEST">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:transform>
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
Expand All @@ -67,7 +67,7 @@ output application/json
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_FOUND">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:transform>
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
Expand All @@ -80,7 +80,7 @@ output application/json
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:METHOD_NOT_ALLOWED">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:transform>
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
Expand All @@ -93,7 +93,7 @@ output application/json
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_ACCEPTABLE">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:transform>
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
Expand All @@ -106,7 +106,7 @@ output application/json
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:UNSUPPORTED_MEDIA_TYPE">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:transform>
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
Expand All @@ -119,7 +119,7 @@ output application/json
</ee:transform>
</on-error-propagate>
<on-error-propagate type="APIKIT:NOT_IMPLEMENTED">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:transform>
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
Expand All @@ -146,7 +146,7 @@ output application/json
<apikit:console config-ref="net-tools-config" />
<error-handler>
<on-error-propagate type="APIKIT:NOT_FOUND">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<ee:transform>
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/json
Expand All @@ -173,7 +173,7 @@ NetworkUtils::curl(attributes.queryParams.url)]]></ee:set-payload>
</ee:transform>
</flow>
<flow name="get:\dns:net-tools-config">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd" doc:id="2eb37294-21d7-412a-8ab6-8da73008b111">
<ee:transform>
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/java
Expand All @@ -195,7 +195,7 @@ NetworkUtils::ping(attributes.queryParams.host)]]></ee:set-payload>
</ee:transform>
</flow>
<flow name="get:\socket:net-tools-config">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd" doc:id="38147a29-0fe5-47f2-ba74-135f9392ecd3">
<ee:transform>
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/java
Expand Down Expand Up @@ -228,9 +228,7 @@ NetworkUtils::cipherTest(attributes.queryParams.host, attributes.queryParams.por
</ee:transform>
</flow>
<flow name="get:\traceroute:net-tools-config">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd" doc:id="a006967e-8161-45f9-af3b-d1f3386ae267">
<ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/java
Expand All @@ -240,4 +238,15 @@ NetworkUtils::traceRoute(attributes.queryParams.host)]]></ee:set-payload>
</ee:message>
</ee:transform>
</flow>
<flow name="get:\traceroutePort:net-tools-config" doc:id="8e725dad-59c4-4713-9771-91a850e9ce9d" >
<ee:transform doc:name="Transform Message" doc:id="70af9c23-b034-40fc-ab42-7781c55b85e3" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/java
import java!com::mulesoft::tool::network::NetworkUtils
---
NetworkUtils::traceRouteWithPort(attributes.queryParams.host, attributes.queryParams.port)]]></ee:set-payload>
</ee:message>
</ee:transform>
</flow>
</mule>
26 changes: 26 additions & 0 deletions src/main/resources/api/net-tools.raml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,32 @@ securitySchemes:
9 216.239.50.189 1.963 ms 216.239.54.205 2.139 ms 216.239.49.9 1.962 ms
10 216.239.58.213 2.424 ms 64.233.174.43 2.246 ms 216.239.58.215 1.577 ms
11 8.8.8.8 1.824 ms 1.383 ms 1.339 ms
/traceroutePort:
get:
description: Runs a traceroute test from the Mule host to the specified endpoint
queryParameters:
host:
description: The domain or ip of the host to traceroute
type: string
port:
description: The port number of host to traceroute
type: number
responses:
200:
body:
text/plain:
example: |
1 216.182.237.132 1.203 ms 216.182.237.128 1.185 ms 216.182.237.132 1.681 ms
2 100.64.1.13 1.671 ms 100.64.1.235 1.337 ms 100.64.1.205 1.649 ms
3 100.64.0.184 469.084 ms 100.64.0.210 992.624 ms 100.64.0.216 1012.502 ms
4 100.64.16.43 0.777 ms 100.64.16.47 0.940 ms 100.64.16.91 0.904 ms
5 72.21.222.221 1.588 ms 72.21.222.223 1.561 ms 72.21.222.221 1.581 ms
6 54.240.242.42 12.569 ms 54.240.243.142 3.572 ms 54.240.242.102 18.003 ms
7 54.240.243.93 1.225 ms 54.240.242.13 1.249 ms 1.244 ms
8 52.95.216.113 1.092 ms 0.878 ms 0.972 ms
9 216.239.50.189 1.963 ms 216.239.54.205 2.139 ms 216.239.49.9 1.962 ms
10 216.239.58.213 2.424 ms 64.233.174.43 2.246 ms 216.239.58.215 1.577 ms
11 8.8.8.8 1.824 ms 1.383 ms 1.339 ms
/dns:
get:
description: Resolves the specified endpoint's IP using the hosts DNS servers
Expand Down
12 changes: 9 additions & 3 deletions src/main/resources/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
<select name="operation" id="operation">
<option value="ping" selected>Ping</option>
<option value="traceroute">Traceroute</option>
<option value="traceroutePort">Traceroute with port</option>
<option value="socket">Socket</option>
<option value="dns">DNS</option>
<option value="curl">curl</option>
Expand Down Expand Up @@ -199,6 +200,11 @@
$("#ip").show();
$("#tracerouteHelp").show();
break;
case "traceroutePort":
$("#ip").show();
$("#port").show();
$("#socketHelp").show();
break;
case "socket":
$("#ip").show();
$("#port").show();
Expand Down Expand Up @@ -236,14 +242,14 @@
var operation = $("#operation").val();
var ip = $("#ip").val();
var url = (operation === 'curl') ? $("#url").val() : '';
var port = (operation === 'socket' || operation === 'certest' || operation === 'ciphertest') ? $("#port").val() : '';
var port = (operation === 'socket' || operation === 'traceroutePort' || operation === 'certest' || operation === 'ciphertest') ? $("#port").val() : '';
var dnsServer = (operation === 'dns') ? $("#dnsServer").val() : '';
if (operation !== 'curl' && !ip) {
toastr["error"]("Missing IP", "Invalid Arguments")
console.error("Missing IP!");
return;
}
if ((operation === 'socket' || operation === 'certest' || operation === 'ciphertest') && !port) {
if ((operation === 'socket' || operation === 'traceroutePort' || operation === 'certest' || operation === 'ciphertest') && !port) {
toastr["error"]("Missing port", "Invalid Arguments")
console.error('Missing port!');
return;
Expand All @@ -254,7 +260,7 @@
return;
}
var apiurl = 'api/' + operation + '?host=' + ip;
if (operation === 'socket' || operation === 'certest' || operation === 'ciphertest') {
if (operation === 'socket' || operation === 'traceroutePort' || operation === 'certest' || operation === 'ciphertest') {
apiurl += '&port=' + port;
}
if (operation === 'dns') {
Expand Down