Error during SonarScanner CLI execution

C:\Users\stl_sdd_phonesavanh\Documents\NetBeansProjects\JavaApplicationAPI>sonar-scanner -X
09:31:56.683 INFO  Scanner configuration file: C:\Users\stl_sdd_phonesavanh\Downloads\Security\Sonar-scanner_cli\sonar-scanner-6.1.0.4477-windows-x64\bin\..\conf\sonar-scanner.properties
09:31:56.700 INFO  Project root configuration file: NONE
09:31:56.700 INFO  SonarScanner CLI 6.1.0.4477
09:31:56.716 INFO  Java 17.0.11 Eclipse Adoptium (64-bit)
09:31:56.717 INFO  Windows 10 10.0 amd64
09:31:56.717 DEBUG Scanner max available memory: 1 GB
09:31:56.733 DEBUG Create: C:\Users\stl_sdd_phonesavanh\.sonar\cache
09:31:56.733 INFO  User cache: C:\Users\stl_sdd_phonesavanh\.sonar\cache
09:31:56.733 DEBUG Create: C:\Users\stl_sdd_phonesavanh\.sonar\cache\_tmp
09:31:56.968 DEBUG Successfully loaded KeyStore of the type [Windows-ROOT] having [60] entries
09:31:56.968 DEBUG Failed to load KeyStore of the type [Windows-ROOT-LOCALMACHINE]
09:31:57.101 DEBUG Successfully loaded KeyStore of the type [Windows-ROOT-CURRENTUSER] having [60] entries
09:31:57.116 DEBUG Successfully loaded KeyStore of the type [Windows-MY] having [0] entries
09:31:57.116 DEBUG Successfully loaded KeyStore of the type [Windows-MY-CURRENTUSER] having [0] entries
09:31:57.116 DEBUG Failed to load KeyStore of the type [Windows-MY-LOCALMACHINE]
09:31:57.116 DEBUG Loaded [120] system trusted certificates
09:31:57.307 DEBUG --> GET http://localhost:9000/api/v2/analysis/version
09:31:57.354 DEBUG <-- HTTP FAILED: java.net.ConnectException: Failed to connect to localhost/[0:0:0:0:0:0:0:1]:9000
09:31:57.354 DEBUG --> GET http://localhost:9000/api/server/version
09:31:57.372 DEBUG <-- HTTP FAILED: java.net.ConnectException: Failed to connect to localhost/[0:0:0:0:0:0:0:1]:9000
09:31:57.374 INFO  EXECUTION FAILURE
09:31:57.378 INFO  Total time: 0.692s
09:31:57.383 ERROR Error during SonarScanner CLI execution
java.lang.IllegalStateException: Failed to get server version
        at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.getServerVersion(ScannerEngineBootstrapper.java:148)
        at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.bootstrap(ScannerEngineBootstrapper.java:112)
        at org.sonarsource.scanner.cli.Main.analyze(Main.java:75)
        at org.sonarsource.scanner.cli.Main.main(Main.java:63)
Caused by: java.lang.IllegalStateException: Call to URL [http://localhost:9000/api/v2/analysis/version] failed
        at org.sonarsource.scanner.lib.internal.http.ServerConnection.callUrl(ServerConnection.java:178)
        at org.sonarsource.scanner.lib.internal.http.ServerConnection.callApi(ServerConnection.java:145)
        at org.sonarsource.scanner.lib.internal.http.ServerConnection.callRestApi(ServerConnection.java:123)
        at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.getServerVersion(ScannerEngineBootstrapper.java:143)
        ... 3 common frames omitted
Caused by: java.net.ConnectException: Failed to connect to localhost/[0:0:0:0:0:0:0:1]:9000
        at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:297)
        at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:207)
        at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:226)
        at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
        at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
        at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
        at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
        at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
        at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
        at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
        at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.kt:221)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
        at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
        at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154)
        at org.sonarsource.scanner.lib.internal.http.ServerConnection.callUrl(ServerConnection.java:176)
        ... 6 common frames omitted
        Suppressed: java.net.ConnectException: Failed to connect to localhost/127.0.0.1:9000
                ... 25 common frames omitted
        Caused by: java.net.ConnectException: Connection refused: getsockopt
                at java.base/sun.nio.ch.Net.pollConnect(Native Method)
                at java.base/sun.nio.ch.Net.pollConnectNow(Unknown Source)
                at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(Unknown Source)
                at java.base/sun.nio.ch.NioSocketImpl.connect(Unknown Source)
                at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
                at java.base/java.net.Socket.connect(Unknown Source)
                at okhttp3.internal.platform.Platform.connectSocket(Platform.kt:128)
                at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:295)
                ... 24 common frames omitted
Caused by: java.net.ConnectException: Connection refused: getsockopt
        at java.base/sun.nio.ch.Net.pollConnect(Native Method)
        at java.base/sun.nio.ch.Net.pollConnectNow(Unknown Source)
        at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(Unknown Source)
        at java.base/sun.nio.ch.NioSocketImpl.connect(Unknown Source)
        at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
        at java.base/java.net.Socket.connect(Unknown Source)
        at okhttp3.internal.platform.Platform.connectSocket(Platform.kt:128)
        at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:295)
        ... 24 common frames omitted

SonarQube how to fix errror this ^

Hey there.

Are you actually able to access http://localhost:9000/api/server/version on the machine where you’re running the scanner? Do you have a SonarQube server started?