File tree 1 file changed +19
-1
lines changed
backend/web/src/main/java/org/jumpserver/chen/web/service/impl
1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 14
14
import org .jumpserver .wisp .ServiceOuterClass ;
15
15
import org .springframework .stereotype .Service ;
16
16
17
+ import java .net .InetAddress ;
18
+ import java .net .UnknownHostException ;
17
19
import java .time .Instant ;
18
20
19
21
@ Service
@@ -97,10 +99,26 @@ private ServiceOuterClass.TokenResponse getTokenResponse(String token) {
97
99
}
98
100
}
99
101
102
+ public static String getIPAddressType (String host ) {
103
+ try {
104
+ InetAddress address = InetAddress .getByName (host );
105
+ if (address .getHostAddress ().contains (":" )) {
106
+ return "IPv6" ;
107
+ } else {
108
+ return "IPv4" ;
109
+ }
110
+ } catch (UnknownHostException e ) {
111
+ return "Unknown" ;
112
+ }
113
+ }
114
+
100
115
private Datasource createDatasource (ServiceOuterClass .TokenResponse tokenResp ) {
101
116
DBConnectInfo dbConnectInfo = new DBConnectInfo ();
102
117
103
- dbConnectInfo .setHost (tokenResp .getData ().getAsset ().getAddress ());
118
+ var address = getIPAddressType (dbConnectInfo .getHost ()).equals ("IPv6" ) ?
119
+ dbConnectInfo .getHost () : String .format ("[%s]" , dbConnectInfo .getHost ());
120
+
121
+ dbConnectInfo .setHost (address );
104
122
dbConnectInfo .setPort (tokenResp .getData ().getAsset ().getProtocols (0 ).getPort ());
105
123
dbConnectInfo .setDbType (tokenResp .getData ().getAsset ().getProtocols (0 ).getName ().toLowerCase ());
106
124
dbConnectInfo .setUser (tokenResp .getData ().getAccount ().getUsername ());
You can’t perform that action at this time.
0 commit comments