@@ -68,3 +68,11 @@ export function deleteBatchPortPool(ids) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function portAvailable(query) {
|
||||
return request({
|
||||
url: '/port-pool/port-available',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
@@ -142,12 +142,6 @@
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<!--<el-form-item :label="$t('服务端端口')" prop="serverPort">
|
||||
<el-select style="width: 280px;" class="filter-item" v-model="temp.serverPort" placeholder="请选择" filterable>
|
||||
<el-option v-for="item in serverPortList" :key="item.port" :label="item.port" :value="item.port">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>-->
|
||||
<el-form-item :label="$t('服务端端口')" prop="serverPort" >
|
||||
<load-select style="width: 280px;" class="filter-item"
|
||||
v-model="temp.serverPort"
|
||||
@@ -198,7 +192,7 @@
|
||||
|
||||
<script>
|
||||
import { fetchList, createUserPortMapping, updateUserPortMapping, updateEnableStatus, deletePortMapping } from '@/api/portMapping'
|
||||
import { portPoolList, availablePortList } from '@/api/portPool'
|
||||
import { portPoolList, availablePortList, portAvailable } from '@/api/portPool'
|
||||
import { licenseList, licenseAuthList } from '@/api/license'
|
||||
import { protocalList } from '@/api/protocal'
|
||||
import { userList } from '@/api/user'
|
||||
@@ -234,6 +228,16 @@ export default {
|
||||
loadSelect
|
||||
},
|
||||
data() {
|
||||
let isPortAvailable = (rule, value, callback) => {
|
||||
if(value!=null){
|
||||
let param = {port: value}
|
||||
portAvailable(param).then(res => {
|
||||
if(!res.data.data){
|
||||
return callback(new Error('该端口被占用'));
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
return {
|
||||
tableKey: 0,
|
||||
list: null,
|
||||
@@ -287,7 +291,8 @@ export default {
|
||||
pvData: [],
|
||||
rules: {
|
||||
licenseId: [{ required: true, message: '请选择License', trigger: 'blur,change' }],
|
||||
serverPort: [{ required: true, message: '请输入服务端端口', trigger: 'blur' }],
|
||||
serverPort: [{ required: true, message: '请输入服务端端口', trigger: 'blur' },
|
||||
{ validator: isPortAvailable, trigger: 'change' }],
|
||||
clientIp: [{ required: true, message: '请输入客户端IP', trigger: 'blur' }],
|
||||
clientPort: [{ required: true, message: '请输入客户端端口', trigger: 'blur' }],
|
||||
protocal: [{ required: true, message: '请选择协议', trigger: 'blur' }]
|
||||
@@ -572,7 +577,7 @@ export default {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
+8
@@ -133,4 +133,12 @@ public class PortPoolController {
|
||||
|
||||
portPoolService.deleteBatch(req.getIds());
|
||||
}
|
||||
|
||||
@Get
|
||||
@Mapping("/port-available")
|
||||
public boolean portAvailable(Integer port) {
|
||||
ParamCheckUtil.checkNotNull(port, "port");
|
||||
|
||||
return portPoolService.portAvailable(port);
|
||||
}
|
||||
}
|
||||
|
||||
+10
@@ -28,6 +28,7 @@ import org.apache.ibatis.solon.annotation.Db;
|
||||
import org.dromara.neutrinoproxy.server.controller.req.system.*;
|
||||
import org.dromara.neutrinoproxy.server.controller.res.system.*;
|
||||
import org.dromara.neutrinoproxy.server.dal.entity.PortGroupDO;
|
||||
import org.dromara.neutrinoproxy.server.util.PortAvailableUtil;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
@@ -198,4 +199,13 @@ public class PortPoolService {
|
||||
visitorChannelService.updateVisitorChannelByPortPool(portPoolDO.getPort(), EnableStatusEnum.DISABLE.getStatus());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查端口是否被占用
|
||||
* @param port
|
||||
* @return
|
||||
*/
|
||||
public boolean portAvailable(Integer port) {
|
||||
return PortAvailableUtil.isPortAvailable(port);
|
||||
}
|
||||
}
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package org.dromara.neutrinoproxy.server.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
|
||||
/**
|
||||
* 检查端口是否被占用
|
||||
* 文章参考:https://blog.csdn.net/xingluxiaoseng/article/details/40148527
|
||||
*/
|
||||
public class PortAvailableUtil {
|
||||
|
||||
private static void bindPort(String host, int port) throws IOException {
|
||||
Socket s = new Socket();
|
||||
s.bind(new InetSocketAddress(host, port));
|
||||
s.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 端口占用判断,若是端口被占用,则会抛出IOException异常,表示端口被占用
|
||||
* @param port
|
||||
* @return
|
||||
*/
|
||||
public static boolean isPortAvailable(int port) {
|
||||
try {
|
||||
bindPort("0.0.0.0", port);
|
||||
bindPort(InetAddress.getLocalHost().getHostAddress(), port);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("端口被占用:"+isPortAvailable(9527));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user