Хорошо. Обмен и использование hostednetwork может быть стрессом. Вот как я это сделал.
Использование командной строки и powershell для достижения необходимых целей.
Конечно, это может быть достигнуто только с PowerShell, но эй ... возможно позже.
Сохраните следующий (BATCH FILE) файл как * .bat. Измените соответственно, где это читает
YOURPATH\YOURFILE.ps1
Сохраните второй файл (PS1 FILE) с именем, которое вы указали в предыдущем шаге
"YOURFILE.ps1"
Измените первый раздел файла PS1 и измените адаптеры в соответствии с вашей системой
$wifi = "description='Broadcom 4313 802.11b/g/n'"
$ethernet = "description='Intel(R) 82577LC Gigabit Network Connection'"
Вы можете запустить свою команду в powershell
Get-WmiObject win32_networkadapterconfiguration | выберите описание
Предполагается, что он имеет только один подключенный интерфейс - физический (Ethernet) или беспроводной.
Запустите пакетный файл от имени администратора.
Кроме того, вы можете запустить процесс из контекстного меню проводника Windows для простоты.
Для этого используйте третий файл и сохраните его как reg и запустите или измените вручную из образца
Само собой разумеется, что необходимо изменить, где это читает
YOURPATH\BATCHFILE.bat
Наслаждаться. ура
-------------------------------------------- Пакетный файл
@echo off
echo Current Settings (netsh wlan show hostednetwork):
netsh wlan show hostednetwork | findstr -i status
rem echo Current Settings
rem echo ######################
rem echo .
echo SSID Name
netsh wlan show hostednetwork | findstr -i " ssid "
netsh wlan show hostednetwork setting=security
echo ######################
echo # #
echo # Please select #
echo # #
echo # [E] Edit #
echo # [S] Start #
echo # [Q] Stop #
echo # [V] View #
echo # #
echo ######################
choice /C ESQV
IF errorlevel 4 goto TetherView
IF errorlevel 3 goto TetherStop
IF errorlevel 2 goto TetherStart
IF errorlevel 1 goto TetherEdit
rem GOTO TetherEnd
:TetherEdit
echo "Please enter SSID:"
set /p SSID=
echo "SSID Password"
set /p PassWord=
echo %SSID% %PassWord%
netsh wlan set hostednetwork mode=allow ssid=%SSID% key=%PassWord%
netsh wlan start hostednetwork
GOTO TetherEnd
:TetherStart
netsh wlan start hostednetwork
powershell -file YOURPATH\ICS-Control.ps1 enable
GOTO TetherEnd
:TetherStop
netsh wlan stop hostednetwork
powershell -file YOURPATH\ICS-Control.ps1 disable
GOTO TetherEnd
:TetherView
cls
netsh wlan show hostednetwork | findstr -i status
echo SSID Name
netsh wlan show hostednetwork | findstr -i " ssid "
netsh wlan show hostednetwork setting=security
echo Connected clients
arp -a | findstr -i 192.168.173 | findstr /V 255 | findstr /V 192.168.173.1
GOTO TetherEnd
:TetherEnd
@PAUSE
-------------------------------------------- ФАЙЛ PS1
#Change accordingly
$wifi = "description='Broadcom 4313 802.11b/g/n'"
$ethernet = "description='Intel(R) 82577LC Gigabit Network Connection'"
#Doesnt change so no need to alter. Detects what interface is connected (should be only one)
$netAdapter = get-wmiobject win32_networkadapter -filter "netconnectionstatus = 2" | select netconnectionid, name, InterfaceIndex, netconnectionstatus
if ($netAdapter.netconnectionid -cmatch "Wi-Fi"){$publicAdapter = $wifi} else {$publicAdapter = $ethernet}
$privateAdapter = "description='Microsoft Hosted Network Virtual Adapter'"
Function Var1ICSenable
{
$virtualAdapter = Get-WMIObject win32_networkadapterconfiguration | where {$_.ServiceName -eq "vwifimp"} | % {$_.GetRelated('win32_networkadapter')} | Select -ExpandProperty Name
$vars1 = $privateAdapter
$Adapter0 = Get-WmiObject Win32_NetworkAdapterConfiguration -Filter $vars1 | select description
$mAdapter3 = $Adapter0 -replace "@{description=",""
$mAdapter3 = $mAdapter3 -replace "}",""
$mAdapter4 = "description='$mAdapter3'"
$mAdapter5 = gwmi win32_networkadapter -Filter $mAdapter4 |select netconnectionid
$mAdapter5 = $mAdapter5 -replace "@{netconnectionid=",""
$global:mAdapter5 = $mAdapter5 -replace "}",""
}
Function Var2ICSenable
{
$vars2 = $publicAdapter
$Adapter1 = Get-WmiObject Win32_NetworkAdapterConfiguration -Filter $vars2 | select description
$mAdapter = $Adapter1 -replace "@{description=",""
$mAdapter = $mAdapter -replace "}",""
$mAdapter1 = "description='$mAdapter'"
$mAdapter2 = gwmi win32_networkadapter -Filter $mAdapter1 |select netconnectionid
$mAdapter2 = $mAdapter2 -replace "@{netconnectionid=",""
$global:mAdapter2 = $mAdapter2 -replace "}",""
}
function EnableDisableICS
{
$bFound = $FALSE
$oNetSharingManager = new-object -comobject HNetCfg.HNetShare
if ($oNetSharingManager -eq $null)
{
write-host "Unable to get the HNetCfg.HnetShare object."
Exit
}
if ($oNetSharingManager.SharingInstalled -eq $null)
{
write-host "Sharing is not available on this platform."
Exit
}
$oConnectionCollection = $oNetSharingManager.EnumEveryConnection
foreach ($oItem In $oConnectionCollection)
{
$EveryConnection = $oNetSharingManager.INetSharingConfigurationForINetConnection($oItem)
$objNCProps = $oNetSharingManager.NetConnectionProps($oItem)
If ($objNCProps.name -eq $sPrivateConnectionName)
{
$bFound = $True
write-host "Setting ICS Private to " $bEnable " on connection: " $objNCProps.name
If ($bEnable -eq "true")
{
$EveryConnection.EnableSharing(1)
}
Else
{
$EveryConnection.DisableSharing()
}
}
}
$oConnectionCollection = $oNetSharingManager.EnumEveryConnection
foreach ($oItem In $oConnectionCollection)
{
$EveryConnection = $oNetSharingManager.INetSharingConfigurationForINetConnection($oItem)
$objNCProps = $oNetSharingManager.NetConnectionProps($oItem)
If ($objNCProps.name -eq $sPublicConnectionName)
{
$bFound = $True
write-host "Setting ICS Public to " $bEnable " on connection: " $objNCProps.name
If ($bEnable -eq "true")
{
$EveryConnection.EnableSharing(0)
}
Else
{
$EveryConnection.DisableSharing()
}
}
}
If ($bFound -eq $null)
{
write-host "Unable to find the connection " + $sPublicConnectionName
}
}
Function EnableSharing
{
#regsvr32 /s hnetcfg.dll
# Variables to enable and disable ICS
Var1ICSenable
Var2ICSenable
$global:firstICSvar = $global:mAdapter2
$global:secondICSvar = $global:mAdapter5
$benable = "true"
$sPublicConnectionName = $global:firstICSvar
$sPrivateConnectionName = $global:secondICSvar
$mstr = $sPublicConnectionName + " " + $sPrivateConnectionName + " " + $bEnable
EnableDisableICS $mstr
}
Function DisableSharing
{
#regsvr32 /s hnetcfg.dll
# Variables to enable and disable ICS
Var1ICSenable
Var2ICSenable
$global:firstICSvar = $global:mAdapter2
$global:secondICSvar = $global:mAdapter5
$benable = "false"
$sPublicConnectionName = $global:firstICSvar
$sPrivateConnectionName = $global:secondICSvar
$mstr = $sPublicConnectionName + " " + $sPrivateConnectionName + " " + $bEnable
EnableDisableICS $mstr
#write-host "TESTE" $mstr
}
if ($args[0] -eq "enable"){EnableSharing}else{DisableSharing}
-------------------------------------------- REG FILE
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\runas]
@="Tether (Hosted Network)"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\runas\command]
@="cmd.exe /c YOURPATH\BATCHFILE.bat"