use of com.helger.network.port.ENetworkProtocol in project ph-web by phax.
the class MainCreateDefaultPorts method main.
public static void main(final String[] args) throws Exception {
final StringBuilder aSB = new StringBuilder();
final IMicroDocument aDoc = MicroReader.readMicroXML(new File("src/test/resources/Service Name and Transport Protocol Port Number Registry.xml"));
for (final IMicroElement aRecord : aDoc.getDocumentElement().getAllChildElements("record")) {
final String sProtocol = MicroHelper.getChildTextContent(aRecord, "protocol");
final ENetworkProtocol eProtocol = ENetworkProtocol.getFromIDOrNull(sProtocol);
if (eProtocol == null) {
// E.g. sctp
continue;
}
final String sNumber = MicroHelper.getChildTextContent(aRecord, "number");
if (sNumber == null)
continue;
int nMin;
int nMax;
if (sNumber.indexOf('-') > 0) {
final String[] aParts = StringHelper.getExplodedArray('-', sNumber, 2);
nMin = StringParser.parseInt(aParts[0], -1);
if (nMin < 0)
throw new IllegalStateException("From part of '" + sNumber + "' is unknown");
nMax = StringParser.parseInt(aParts[1], -1);
if (nMax < 0)
throw new IllegalStateException("To part of '" + sNumber + "' is unknown");
} else {
final int nNumber = StringParser.parseInt(sNumber, -1);
if (nNumber < 0)
throw new IllegalStateException("Number '" + sNumber + "' is unknown");
nMin = nMax = nNumber;
}
final String sName = StringHelper.getNotNull(MicroHelper.getChildTextContent(aRecord, "name"));
final String sDescription = StringHelper.getNotNull(MicroHelper.getChildTextContent(aRecord, "description"));
if ("Unassigned".equals(sDescription))
continue;
if (sDescription.contains("IANA assigned this well-formed service name as a replacement for"))
continue;
for (int nPort = nMin; nPort <= nMax; ++nPort) {
if (nPort < 1024)
aSB.append("public static final INetworkPort " + eProtocol.name() + "_" + nPort + (StringHelper.hasText(sName) ? "_" + _id(sName) : "") + " = _registerPort (" + nPort + ", ENetworkProtocol." + eProtocol.name() + ", " + _quote(sName) + ", " + _quote(sDescription) + ");\n");
}
}
LOGGER.info(aSB.toString());
}
use of com.helger.network.port.ENetworkProtocol in project ph-web by phax.
the class MainPortScanner method main.
public static void main(final String[] args) {
final int nStartPort = CNetworkPort.MINIMUM_PORT_NUMBER;
final int nEndPort = CNetworkPort.MAXIMUM_PORT_NUMBER;
final EnumSet<ENetworkProtocol> aTypes = EnumSet.allOf(ENetworkProtocol.class);
final StopWatch aSW = StopWatch.createdStarted();
for (int nPort = nStartPort; nPort <= nEndPort; ++nPort) for (final ENetworkProtocol eType : aTypes) {
final int nFinalPort = nPort;
final boolean bIsUsed = eType.isPortUsed(nPort);
if (bIsUsed) {
LOGGER.info(eType.name() + " Port " + nPort + " is used");
DefaultNetworkPorts.forEachPort(x -> x.getPort() == nFinalPort && x.getProtocol() == eType, x -> LOGGER.info(" " + StringHelper.getConcatenatedOnDemand(x.getName(), ": ", x.getDescription())));
}
}
aSW.stop();
final int nCount = (nEndPort - nStartPort) * aTypes.size();
LOGGER.info(nCount + " ports checked in " + aSW.getMillis() + " ms");
}
Aggregations