Comments (4)
Rough draft of splitting your md output
using Microsoft.Extensions.Logging;
using System.Text.RegularExpressions;
namespace File_Folder_Helper.Day;
internal static partial class Helper20231205
{
[GeneratedRegex(@"[\\,\/,\:,\*,\?,\"",\<,\>,\|]")]
private static partial Regex WindowsSafe();
private static string? GetStrippedIPV4(string[] segments)
{
string? result = null;
string[] subSegments;
foreach (string segment in segments)
{
subSegments = segment.Split('.');
if (subSegments.Length != 4)
continue;
if (!subSegments.All(l => int.TryParse(l, out _)))
continue;
result = segment.Replace(".", string.Empty);
}
return result;
}
private static string? GetStrippedMacAddress(string[] segments)
{
string? result = null;
foreach (string segment in segments)
{
if (segment.Length != 17)
continue;
if (segment[2] is not ':' or '-' || segment[5] is not ':' or '-' || segment[8] is not ':' or '-' || segment[11] is not ':' or '-' || segment[14] is not ':' or '-')
continue;
result = $"{segment[0]}{segment[1]}{segment[3]}{segment[4]}{segment[6]}{segment[7]}{segment[9]}{segment[10]}{segment[12]}{segment[13]}{segment[15]}{segment[16]}";
}
return result;
}
internal static void SplitMarkdownFile(ILogger<Worker> logger, List<string> args)
{
string[] lines;
string? fileName;
string[] segments;
string checkFileName;
string? strippedIpV4;
string? strippedMacAddress;
List<string> collection = [];
string sourceDirectory = args[0];
if (!Directory.Exists(sourceDirectory))
throw new Exception(sourceDirectory);
string outputDirectory = Path.Combine(sourceDirectory, "Output");
if (!Directory.Exists(outputDirectory))
_ = Directory.CreateDirectory(outputDirectory);
string[] files = Directory.GetFiles(args[0], args[2], SearchOption.TopDirectoryOnly);
foreach (string file in files)
{
fileName = null;
collection.Clear();
lines = File.ReadAllLines(file);
foreach (string line in lines)
{
collection.Add(line);
if (line.Length > 0 && line[0] == '#' && line.StartsWith("## "))
{
segments = line.Split(' ');
strippedIpV4 = GetStrippedIPV4(segments);
strippedMacAddress = GetStrippedMacAddress(segments);
if (strippedMacAddress is null && strippedIpV4 is null)
fileName = $"{WindowsSafe().Replace(line[3..], "-").Trim()}.md";
else if (strippedMacAddress is null)
{
fileName = $"{strippedIpV4}.md";
collection.Insert(0, string.Empty);
collection.Insert(0, $"# {fileName}");
}
else
{
fileName = $"{strippedMacAddress}.md";
collection.Insert(0, string.Empty);
collection.Insert(0, $"# {fileName}");
}
}
if (fileName is null || line != "----")
continue;
logger.LogInformation("{fileName} created", fileName);
checkFileName = Path.Combine(outputDirectory, fileName);
if (File.Exists(checkFileName))
File.Delete(checkFileName);
File.WriteAllLines(checkFileName, collection);
collection.Clear();
}
}
}
}
from nmap-formatter.
Hey @mikepharesjr , thanks for taking an interest in the project. I actually think of something more simpler than that. Maybe something that can be solved with simple command calls:
hosts=$(cat nmap.xml | nmap-formatter json | jq -r '[select-only-hostnames-from-json]' | uniq)
# for each host
cat nmap.xml | nmap-formatter md --filter-host-addr $host > host_$host.md
I think I can introduce something like --filter-[entity-name]
, what do you think?
from nmap-formatter.
Hello @vdjagilev, thank you for reviewing the request.
My rough draft to parse the current output is missing updating the toc markdown to point to the new file.
Yes, I think what you are purposing would work.
Would this also work with MAC address?
from nmap-formatter.
@mikepharesjr yeah, I think it's possible to implement it with something like this --filter-mac "00:AB:BC..."
from nmap-formatter.
Related Issues (20)
- Add missing 'dot' format to Use in cobra.Command struct
- Upgrade CodeQL to v2
- Wiki: Add more information about installation
- Issues in HTML template
- Cannot use the latest version with Go install
- Update go version & dependencies
- Add sqlite support HOT 1
- Update golang to 1.20
- Update Node.js 12 -> 16 for pipelines
- OS class have multiple values
- Wiki: Is it possible to use the library to create csv output as well HOT 1
- Long lines troubles HOT 3
- Implementation of filters
- Possibility to remove TOC/header in md/html templates
- Update license file
- Add a separate function to check if host is up
- Pipelines: Fix some warnings
- Support for d2
- Update golang to 1.22
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nmap-formatter.