How to do same as 'nmap' command from within a D program?
forkit
forkit at gmail.com
Sat Jan 22 23:15:18 UTC 2022
On Saturday, 22 January 2022 at 22:44:31 UTC, forkit wrote:
>
and here is how to get the ip (depending on the formatting of
your output of course)
// ---
module test;
import std;
void main()
{
auto result = execute(["bash", "-c", "nmap -sn
192.168.11.0/24 | ack -B2 \"Philips\""]);
string ip;
if(canFind(result.to!string, "Host is up"))
{
writeln("Host is up");
string str = result.to!string.chop;
ip = str[ (indexOf(str, "for Philips (") + 10)..$-4 ];
writeln(ip);
}
else
writeln("Host not found.");
}
// ----
More information about the Digitalmars-d-learn
mailing list