@@ -175,47 +175,19 @@ def __fix_network_interface_in_sockd_conf(self) -> None:
175175 logging .info ("Auto-detecting network interface for SOCKS proxy configuration" )
176176
177177 try :
178- # Get the primary network interface (exclude loopback)
179178 result = subprocess .run (
180- ["ip" , "-o" , "link" , "show" ],
181- capture_output = True ,
182- text = True ,
183- check = True
179+ ["ip" , "-o" , "route" , "get" , "1" ],
180+ capture_output = True , text = True , check = True
184181 )
185-
186- primary_interface = None
187- # Try to find an interface in UP state first
188- for line in result .stdout .split ('\n ' ):
189- if line .strip () and 'lo:' not in line and 'state UP' in line :
190- # Extract interface name (format: "2: ens5: <BROADCAST...")
191- parts = line .split (':' )
192- if len (parts ) >= 2 :
193- primary_interface = parts [1 ].strip ()
194- break
195-
196- if not primary_interface :
197- # Fallback: just get the first non-loopback interface
198- for line in result .stdout .split ('\n ' ):
199- if line .strip () and 'lo:' not in line :
200- parts = line .split (':' )
201- if len (parts ) >= 2 :
202- primary_interface = parts [1 ].strip ()
203- break
204-
205- if not primary_interface :
206- logging .warning ("Could not detect primary network interface, using default 'ens5'" )
207- primary_interface = "ens5"
182+ match = re .search (r'dev\s+(\S+)' , result .stdout )
183+ primary_interface = match .group (1 ) if match else "ens5"
208184
209185 logging .info (f"Detected primary network interface: { primary_interface } " )
210186
211187 with open ('/etc/sockd.conf' , 'r' ) as f :
212188 config = f .read ()
213189
214- new_config = re .sub (
215- r'external:\s+\w+' ,
216- f'external: { primary_interface } ' ,
217- config
218- )
190+ new_config = re .sub (r'external:\s+\w+' , f'external: { primary_interface } ' , config )
219191
220192 with open ('/etc/sockd.conf' , 'w' ) as f :
221193 f .write (new_config )
0 commit comments