loxia01 / PSInternetConnectionSharing

This PowerShell Module provides simple functions to control Windows Internet Connection Sharing (ICS) from command line.
45 stars 8 forks source link

VPN connections missing? #1

Open Owyn opened 3 years ago

Owyn commented 3 years ago

I need to turn off & on ICS for my VPN connection which connects me to the internet, but the program can't seem to see or access it anyhow

image

loxia01 commented 3 years ago

Hello, thanks for posting your issue. Can you try listing your connections with Get-NetAdapter command instead of ipconfig and post a screenshot?

Owyn commented 3 years ago

Obviously VPN connection is not an adapter... it's not there

loxia01 commented 3 years ago

Ok, I believe it is those VPN connections Windows handles "internally" (LPT2/IPsec) that are not showing up as apdaters. If you have a VPN connection via the OpenVPN protocol, an adapter is created for OpenVPN connections (TAP adapter).

Unfortunately I have no means to test ICS for LPT2/IPsec connections right now. Do you know if ICS is supposed to work for LPT2/IPsec connections at all? If it is, the command Get-VpnConnections looks promising to work with in PowerShell.

Owyn commented 3 years ago

I have ICS currently enabled by standard windows means on the LPT2 connection and it works (until PC restart or reconnect then I have to manually disable\enable it again for it to start working again - that's why I need this)

image

loxia01 commented 3 years ago

Is your connection showing up if you run the following command in PowerShell? Get-NetAdapter -IncludeHidden

Owyn commented 3 years ago

it doesn't, only 2 (x5) standard adapters

loxia01 commented 3 years ago

Did you run Get-NetAdapter -IncludeHidden? (I edited the post).

Owyn commented 3 years ago

well, there is no name of my L2TP connection there

image

loxia01 commented 3 years ago

Tested to rewrite my module with Get-NetAdapter -IncludeHidden. I will upload this rewritten module so you can test for yourself. Perhaps you can test to share "Beeline_local" connection. When installing do exactly as before but name the folder "PSInternetConnectionSharing_IncludeHidden". Then add "1" to the function name, like Set-Ics1, Get-Ics1 and Disable-Ics1 when issuing the rewritten commands.

Owyn commented 3 years ago

Perhaps you can test to share "Beeline_local" connection.

That's my local connection without internet, and I need internet to share so sharing it would be kinda pointless...

loxia01 commented 3 years ago

Ok unfortunately I do not know how to fix this for now, but I remember a workaround (or solution) I used myself when I started using ICS: To make ICS persistent across reboots you have to add a value in Windows registry: Run regedit and navigate to HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\SharedAccess. There create New > DWORD (32-bit) Value and name the new key EnableRebootPersistConnection. Doubleclick the key and modify its value to 1. ICS should now be permanent across reboots.

Hope this will work for you.

Source: https://www.thewindowsclub.com/internet-connection-sharing-not-working

obones commented 3 years ago

I have the same issue here, and in the registry, I see that ICS is enabled with an interface index of 51 that Get-NetAdapter never shows. However, this question at ServerFault has the answer:

gwmi MSFT_NetIPAddress -Namespace 'root/standardcimv2' 

In this list, I see all my interfaces, including the VPN one with the appropriate InterfaceAlias and InterfaceIndex value. Note that some interfaces show up multiple times in this list, but at least they are all here.

loxia01 commented 3 years ago

I have the same issue here, and in the registry, I see that ICS is enabled with an interface index of 51 that Get-NetAdapter never shows. However, this question at ServerFault has the answer:

gwmi MSFT_NetIPAddress -Namespace 'root/standardcimv2' 

In this list, I see all my interfaces, including the VPN one with the appropriate InterfaceAlias and InterfaceIndex value. Note that some interfaces show up multiple times in this list, but at least they are all here.

Thanks for your help. I will see if I can get to test this command on an appropriate connection.

MDagni commented 3 years ago

Some info from my side...

I'm using Check Point SSL Network Extender client. It doesn't appear when I say Get-Ics image

It appears with Get-NetAdapter -IncludeHidden image

It doesn't appear in Windows Network Connections. image

I tried a freeware program named MyPublicWiFi. It can share this hidden connection in "Router Mode (NAT)". When it runs like this, the other computer can access the resources on the VPN through this network. But it can't access internet. image

When I try to run it in Internet Connection Sharing (ICS) mode, it says "The Internet Connection Sharing (ICS) can not be enabled". image

So I guess it's not possible to use ICS on this kind of network.

loxia01 commented 3 years ago

@MDagni Thanks for commenting. If it doesn't appear in Control Panel's Network Connections I believe it is not possible to use ICS on that connection. But I am no expert.

loxia01 commented 3 years ago

Beta version v1.1 released. This release has a rewritten connection enumeration command (thanks @obones for the tip) and should be able to work with VPN connections that Windows handle internally, like those using PPTP, L2TP/IPSec and IKEv2 protocols. These connections must be connected in order for the command to work. Unfortunately I am not able to test these connections myself so I am thankful for functionality and bug reports.

Owyn commented 3 years ago

disabling ICS for vpn now works, but enabling it back errors: image

loxia01 commented 3 years ago

Thanks for testing. Try to run this command (Get-CimInstance MSFT_NetIPAddress -Namespace Root\StandardCimv2).InterfaceAlias when ICS is disabled. Make sure your VPN connection is connected beforehand.

Owyn commented 3 years ago
 (Get-CimInstance MSFT_NetIPAddress -Namespace Root\StandardCimv2).InterfaceAlias
Loopback Pseudo-Interface 1
Beeline_L2TP
Beeline_local
Home_local
Loopback Pseudo-Interface 1

it's all in the list (list is the same btw both with ICS enabled and disabled), and yea it's connected.

Owyn commented 3 years ago

I also tried PS script from: https://superuser.com/questions/470319/how-to-enable-internet-connection-sharing-using-command-line#answer-649183 and got the exact same error

loxia01 commented 3 years ago

OK, thanks anyway. I don't know why you get errors. Will try to do some more testing.

loxia01 commented 3 years ago

@Owyn As I have understood it you can enable ICS manually for your VPN connection in Control Panel's Network Connections? Does that work even if your connection is disconnected?

Owyn commented 3 years ago

I can enable my ICS manually just fine independently whether it's connected or not

moreover I've made an AHK macro to turn it off & on cuz powershell was giving the error, and the macro works...

loxia01 commented 3 years ago

OK thanks for your testing.

obones commented 3 years ago

Unfortunately, it appears this is to be expected from ICS on PPPoE connections: https://answers.microsoft.com/en-us/windows/forum/windows_10-networking-winpc/ics-internet-connection-sharing-dosent-work-in/a203c90f-1214-4e5e-ae90-9832ae5ceb55?page=1

The answer from Krisavi on September 29, 2016 gives the exact same error message, and the follow up answers up to the last page do not give much hope on a resolution from Microsoft.

That being said, I modified the registry, in that key : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess I added a DWORD value named EnableRebootPersistConnection with value 1 which is said to persist the ICS parameters across reboots. I'll see if that helps in the following days.

Owyn commented 3 years ago

persist the ICS parameters across reboots.

tried it - it doesn't, and problem isn't only across reboots, but also across reconnects

loxia01 commented 3 years ago

I checked and I have actually not EnableRebootPersistConnection set and my ICS is anyway persistent across reboots. So I guess it is about those problem VPN connections.