2020-04-26 20:54:22 +10:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-04-26 20:54:22 +10:00
|
|
|
*/
|
|
|
|
|
|
2021-05-15 12:34:40 +02:00
|
|
|
#include <AK/Assertions.h>
|
2020-11-15 13:11:21 +01:00
|
|
|
#include <AK/ByteBuffer.h>
|
2020-04-26 20:54:22 +10:00
|
|
|
#include <AK/JsonObject.h>
|
|
|
|
|
#include <LibCore/File.h>
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
auto file = Core::File::construct("/proc/net/arp");
|
2021-05-12 13:56:43 +04:30
|
|
|
if (!file->open(Core::OpenMode::ReadOnly)) {
|
2021-05-31 15:43:25 +01:00
|
|
|
warnln("Failed to open {}: {}", file->name(), file->error_string());
|
2020-04-26 20:54:22 +10:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-31 15:43:25 +01:00
|
|
|
outln("Address HWaddress");
|
2020-04-26 20:54:22 +10:00
|
|
|
auto file_contents = file->read_all();
|
2020-06-10 21:40:27 -07:00
|
|
|
auto json = JsonValue::from_string(file_contents);
|
2021-02-23 20:42:32 +01:00
|
|
|
VERIFY(json.has_value());
|
2020-06-10 21:40:27 -07:00
|
|
|
json.value().as_array().for_each([](auto& value) {
|
2021-05-31 17:59:02 +01:00
|
|
|
auto& if_object = value.as_object();
|
2020-04-26 20:54:22 +10:00
|
|
|
|
|
|
|
|
auto ip_address = if_object.get("ip_address").to_string();
|
|
|
|
|
auto mac_address = if_object.get("mac_address").to_string();
|
|
|
|
|
|
2021-05-31 15:43:25 +01:00
|
|
|
outln("{:15} {:17}", ip_address, mac_address);
|
2020-04-26 20:54:22 +10:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|