package com.example.operating_system.controller;
import com.example.operating_system.Threads.RunnableTest;
import jakarta.websocket.server.PathParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.net.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
@RestController
public class MainController {
/**
* 获取host里的FPort-LPort端口所有状态
* @param host
* @param FPort
* @param LPort
* @return
*/
@GetMapping("/scan/{host}/{FPort}/{LPort}/{type}/{thread}")
public String Scan(@PathVariable("host") String host,
@PathVariable("FPort") String FPort,
@PathVariable("LPort") String LPort,
@PathVariable("type") String type,
@PathVariable("thread") String thread) {
int startPort = Integer.parseInt(FPort);
int endPort = Integer.parseInt(LPort);
int threads = Integer.parseInt(thread);
//创建线程池
ExecutorService service = Executors.newFixedThreadPool(threads);
ThreadPoolExecutor service1 = (ThreadPoolExecutor) service;
//设置线程池属性
service1.setMaximumPoolSize(500);//设置线程池中线程数的上限
for (int port = startPort; port <= endPort; port++) {
service.execute(new RunnableTest(host,port,type));
}
System.out.println("成功调用");
//关闭线程池
service.shutdown();
return "请求成功";
}
/**
* 获取host里的FPort-LPort端口所有状态
* @param host
* @param FPort
* @param LPort
* @return
*/
@GetMapping("/scan/{host}/{FPort}/{LPort}/{type}")
public String Scan(@PathVariable("host") String host,
@PathVariable("FPort") String FPort,
@PathVariable("LPort") String LPort,
@PathVariable("type") String type) {
int startPort = Integer.parseInt(FPort);
int endPort = Integer.parseInt(LPort);
for (int port = startPort; port <= endPort; port++) {
if (TCPisPortOpen(host, port)) {
if (type.equals("close"))
{
continue;
}
String message = "Port " + port + " is open";
System.out.println(message);
ScannerController.broadcast(message);
}
else
{
if (type.equals("open"))
{
continue;
}
String message = "Port " + port + " is closed";
System.out.println(message);
ScannerController.broadcast(message);
}
}
System.out.println("成功调用");
return "请求成功";
}
private static boolean TCPisPortOpen(String host, int port) {
try {
// 创建Socket并尝试连接
Socket socket = new Socket();
socket.connect(new InetSocketAddress(host, port), 1000); // 1000毫秒超时
socket.close();
return true;
} catch (IOException e) {
return false;
}
}
private static boolean UDPisPortOpen(String host, int port)
{
try{
DatagramSocket socket = new DatagramSocket();
socket.setSoTimeout(1000);
byte[] buffer = new byte[1];
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, InetAddress.getByName(host), port);
socket.send(packet);
socket.receive(packet);
System.out.println("Port "+port+ " is open baseUDP");
return true;
}catch (IOException e)
{
System.out.println("Port "+port+ " is close baseUDP");
return false;
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
内容概要:该文件为操作系统课程设计文件,题目为端口扫描程序,压缩包包含一个基于Java,springboot,websocket实现的简单的端口扫描程序。本资源在该平台也有相关的文章解析,在文件上传人的相关博客里,感兴趣可以去看看。 适合人群:在校大学生,在操作系统或其他课程设计题目中有:简单的端口扫描系统的大学生。 能学到什么: ①在springboot中websocket怎么实现 ②使用线程池解决端口扫描问题 阅读建议:此资源为作者端口扫描的文章配套源码,讲述如何一步步实现端口扫描并进行相关优化,额外使用websocket实现对端口扫描结果的实时反馈。建议该资源搭配作者文章进行使用。
资源推荐
资源详情
资源评论
收起资源包目录
Operating_System.zip (42个子文件)
HELP.md 860B
mvnw.cmd 7KB
pom.xml 2KB
src
test
java
com
example
operating_system
OperatingSystemApplicationTests.java 239B
main
resources
application.properties 1B
templates
main.html 16KB
static
js
axios.js 113KB
axios.min.js 40KB
java
com
example
operating_system
OperatingSystemApplication.java 351B
PortScanner.java 2KB
controller
RouterController.java 296B
MainController.java 4KB
ScannerController.java 2KB
Threads
CSDNRunnable.java 1KB
test.java 2KB
scanThread.java 746B
RunnableTest.java 2KB
config
webSocketConfig.java 424B
.mvn
wrapper
maven-wrapper.properties 233B
maven-wrapper.jar 61KB
.idea
jarRepositories.xml 864B
workspace.xml 7KB
misc.xml 644B
compiler.xml 729B
.gitignore 190B
encodings.xml 191B
target
classes
application.properties 1B
templates
main.html 16KB
static
js
axios.js 113KB
axios.min.js 40KB
com
example
operating_system
OperatingSystemApplication.class 790B
PortScanner.class 3KB
controller
MainController.class 4KB
RouterController.class 625B
ScannerController.class 3KB
Threads
test.class 1KB
CSDNRunnable.class 2KB
scanThread.class 973B
RunnableTest.class 2KB
config
webSocketConfig.class 744B
generated-sources
annotations
mvnw 11KB
.gitignore 395B
共 42 条
- 1
资源评论
LimLX
- 粉丝: 213
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- SW3518S全协议快充USB Type-c接口电源模块硬件参考设计评估版硬件(原理图 +pcb)+封装库文件.zip
- 基于深度强化学习算法实现多星对区域目标观测的规划python源码+数据集+模型+超详细注释.zip
- RT1052+SDRAM(IS42S16160) +SIM7600CE(PCIE接口封装)控制板硬件(原理图+PCB)+封装库
- 2017大学英语四级词汇-excel-列表版(精品文档).xls
- 2017版国家医保药品目录(excel版)完整版.xls
- 基于STM32F103单片机设计的无刷电机控制板硬件(原理图+PCB+BOM)+MCU软件控制源码+文档资料.zip
- 肺结节检测数据集VOC+YOLO格式1186张1类别.zip
- Faster-RCNN基于知识蒸馏的目标检测模型增量深度学习方法python源码+项目运行说明.zip
- 2018年考勤表——excel版.xls
- 基于Labview的转子动平衡测控系统源码+系统软件说明书.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功