正在显示
1 个修改的文件
包含
51 行增加
和
12 行删除
| @@ -300,18 +300,21 @@ public class CameraRtspHandle implements CameraHandle { | @@ -300,18 +300,21 @@ public class CameraRtspHandle implements CameraHandle { | ||
| 300 | } | 300 | } |
| 301 | 301 | ||
| 302 | public static void main(String[] args) { | 302 | public static void main(String[] args) { |
| 303 | - ConfigurationParameterService.initConfigurationParameter(); | ||
| 304 | - CameraRtspHandle cameraRtspHandle = new CameraRtspHandle(); | ||
| 305 | - if(cameraRtspHandle.isOpen()) | ||
| 306 | - { | ||
| 307 | - CanvasFrame previewCanvas = new CanvasFrame("摄像头预览", CanvasFrame.getDefaultGamma() / cameraRtspHandle.grabber.getGamma()); | ||
| 308 | - previewCanvas.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
| 309 | - previewCanvas.setAlwaysOnTop(true); | ||
| 310 | - while (true) | ||
| 311 | - { | ||
| 312 | - cameraRtspHandle.pushVideo(filteredFrame -> previewCanvas.showImage(filteredFrame)); | ||
| 313 | - } | ||
| 314 | - } | 303 | + String ips = "192.168.2.2/254"; |
| 304 | + System.out.println(getIpFromParagraph(ips)); | ||
| 305 | + | ||
| 306 | +// ConfigurationParameterService.initConfigurationParameter(); | ||
| 307 | +// CameraRtspHandle cameraRtspHandle = new CameraRtspHandle(); | ||
| 308 | +// if(cameraRtspHandle.isOpen()) | ||
| 309 | +// { | ||
| 310 | +// CanvasFrame previewCanvas = new CanvasFrame("摄像头预览", CanvasFrame.getDefaultGamma() / cameraRtspHandle.grabber.getGamma()); | ||
| 311 | +// previewCanvas.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
| 312 | +// previewCanvas.setAlwaysOnTop(true); | ||
| 313 | +// while (true) | ||
| 314 | +// { | ||
| 315 | +// cameraRtspHandle.pushVideo(filteredFrame -> previewCanvas.showImage(filteredFrame)); | ||
| 316 | +// } | ||
| 317 | +// } | ||
| 315 | 318 | ||
| 316 | } | 319 | } |
| 317 | 320 | ||
| @@ -348,6 +351,10 @@ public class CameraRtspHandle implements CameraHandle { | @@ -348,6 +351,10 @@ public class CameraRtspHandle implements CameraHandle { | ||
| 348 | { | 351 | { |
| 349 | return OperatingData.sysConfig.getCameraIp(); | 352 | return OperatingData.sysConfig.getCameraIp(); |
| 350 | } | 353 | } |
| 354 | + if(StringUtils.isNotEmpty(OperatingData.sysConfig.getParagraphIp())) | ||
| 355 | + { | ||
| 356 | + return getIpFromParagraph(OperatingData.sysConfig.getParagraphIp()); | ||
| 357 | + } | ||
| 351 | String localIP = getLocalIp(); | 358 | String localIP = getLocalIp(); |
| 352 | logger.info("找到的主机ip:"+localIP); | 359 | logger.info("找到的主机ip:"+localIP); |
| 353 | if(null == localIP) | 360 | if(null == localIP) |
| @@ -394,6 +401,38 @@ public class CameraRtspHandle implements CameraHandle { | @@ -394,6 +401,38 @@ public class CameraRtspHandle implements CameraHandle { | ||
| 394 | return null; | 401 | return null; |
| 395 | } | 402 | } |
| 396 | 403 | ||
| 404 | + /** | ||
| 405 | + * 查找可以ip | ||
| 406 | + * @param ips | ||
| 407 | + */ | ||
| 408 | + private static String getIpFromParagraph(String ips) { | ||
| 409 | + try { | ||
| 410 | + String[] ipstart = ips.split("\\."); | ||
| 411 | + String[] endips = ipstart[3].split("/"); | ||
| 412 | + InetAddress startInetAddress = InetAddress.getByName(ipstart[0]+"."+ipstart[1]+"."+ipstart[2]+"."+endips[0]); | ||
| 413 | + | ||
| 414 | + byte[] startBytes = startInetAddress.getAddress(); | ||
| 415 | + | ||
| 416 | + for (int i = Integer.parseInt(endips[0]); i <= Integer.parseInt(endips[1]); i++) { | ||
| 417 | + byte[] scanBytes = new byte[]{startBytes[0], startBytes[1], startBytes[2], (byte) i}; | ||
| 418 | + String ipToScan = InetAddress.getByAddress(scanBytes).getHostAddress(); | ||
| 419 | + | ||
| 420 | + Process process = Runtime.getRuntime().exec("ping -n 1 -w 1 " + ipToScan); | ||
| 421 | + int returnVal = process.waitFor(); | ||
| 422 | + | ||
| 423 | + if (returnVal == 0) { | ||
| 424 | + System.out.println("Ping success: " + ipToScan); | ||
| 425 | + return ipToScan; | ||
| 426 | + } else { | ||
| 427 | + System.out.println("Ping failed: " + ipToScan); | ||
| 428 | + } | ||
| 429 | + } | ||
| 430 | + } catch (Exception e) { | ||
| 431 | + e.printStackTrace(); | ||
| 432 | + } | ||
| 433 | + return null; | ||
| 434 | + } | ||
| 435 | + | ||
| 397 | private static void findCamera(String ip) | 436 | private static void findCamera(String ip) |
| 398 | { | 437 | { |
| 399 | try { | 438 | try { |
-
请 注册 或 登录 后发表评论