| 
									
										
										
										
											2023-02-26 13:59:54 +00:00
										 |  |  | //go:build windows
 | 
					
						
							|  |  |  | // +build windows
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package sys | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2023-05-22 23:13:15 +00:00
										 |  |  | 	"errors" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-17 19:48:49 +00:00
										 |  |  | 	"github.com/shirou/gopsutil/v4/net" | 
					
						
							| 
									
										
										
										
											2023-02-26 13:59:54 +00:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-22 23:13:15 +00:00
										 |  |  | func GetConnectionCount(proto string) (int, error) { | 
					
						
							|  |  |  | 	if proto != "tcp" && proto != "udp" { | 
					
						
							|  |  |  | 		return 0, errors.New("invalid protocol") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	stats, err := net.Connections(proto) | 
					
						
							| 
									
										
										
										
											2023-02-26 13:59:54 +00:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return 0, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return len(stats), nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-22 23:13:15 +00:00
										 |  |  | func GetTCPCount() (int, error) { | 
					
						
							|  |  |  | 	return GetConnectionCount("tcp") | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-26 13:59:54 +00:00
										 |  |  | func GetUDPCount() (int, error) { | 
					
						
							| 
									
										
										
										
											2023-05-22 23:13:15 +00:00
										 |  |  | 	return GetConnectionCount("udp") | 
					
						
							| 
									
										
										
										
											2023-02-26 13:59:54 +00:00
										 |  |  | } |