use of com.infiniteautomation.mango.rest.latest.model.server.NetworkInterfaceModel in project ma-modules-public by infiniteautomation.
the class ServerRestController method getNetworkInterfaces.
@ApiOperation(value = "List network interfaces", notes = "Requires global data source permission")
@RequestMapping(method = { RequestMethod.GET }, value = "/network-interfaces")
@PreAuthorize("isGrantedPermission('permissionDatasource')")
public List<NetworkInterfaceModel> getNetworkInterfaces(@RequestParam(value = "includeLoopback", required = false, defaultValue = "false") boolean includeLoopback, @RequestParam(value = "includeDefault", required = false, defaultValue = "false") boolean includeDefault, @AuthenticationPrincipal PermissionHolder user) {
List<NetworkInterfaceModel> models = new ArrayList<>();
if (includeDefault) {
NetworkInterfaceModel model = new NetworkInterfaceModel();
model.setHostAddress("0.0.0.0");
model.setInterfaceName("");
models.add(model);
}
try {
for (NICInfo ni : HostUtils.getLocalInet4Addresses(includeLoopback)) {
NetworkInterfaceModel model = new NetworkInterfaceModel();
model.setHostAddress(ni.getInetAddress().getHostAddress());
model.setInterfaceName(ni.getInterfaceName());
models.add(model);
}
} catch (SocketException e) {
throw new ServerErrorException(new TranslatableMessage("common.default", e.getMessage()), e);
}
return models;
}
Aggregations