0

I have the following scenario:

PC1 (Windows 10 Home) connected to LAN-only network (currently using a dynamic IP address)

If I try to use a static IP, the connection will occasionally drop half the connection (i.e., I can ping out, but not in when this happens - Also I am unable to SSH out or do anything that involves receiving data). Connectivity is restored when the interface is disabled, then re-enabled. For more information please see previous question: Windows randomly drops half of connection

I'm looking for a script that will detect this state and then run my reset script. I have full administrator access to everything.

The flow chart would ideally look something like this:

Flowchart

1
  • Any suggestions are welcomed.
    – Daniel
    Commented Nov 19, 2015 at 19:51

1 Answer 1

0

Daniel,

the following code will ping the a certain address for you, if this adress is not reachable by ping. The network adapter will be reset

Change n.n.n.n to the desired IP adress that should be pinged, and rename 'Name of the connection' to the used network adapter interface name. Example: 'Ethernet'

$IpAdress = "192.168.0.1"
$ConnectionName = "ethernet"
$Testconnection = test-connection $IpAdress -count 1 -quiet

if(!$Testconnection)
{
 $nic = gwmi win32_networkadapter -filter "NetConnectionID='$ConnectionName'"
  $nic.disable()
  write-host "Disabling Network interface '$ConnectionName''"
  sleep 5
  $nic.enable()
  write-host "Enabling Network interface '$ConnectionName''"
}

Try configuring a scheduled task for the script to run every X of time to check the adapter connectivity. Or just run the script with powershell when you notice the connection is lost.

5
  • Well, this is great, but I can successfully ping a host, but I cannot be pinged be another host.
    – Daniel
    Commented Nov 20, 2015 at 16:06
  • You could run the script from other Windows machines in your network. (if there are any). Adjust the get-wmi line with the -ComputerName "RemoteMachine" parameter to query remote machines.
    – doenoe
    Commented Nov 23, 2015 at 8:39
  • Would it work if I had my local machine query another host on the network? It would fail if the link weren't bidirectional.
    – Daniel
    Commented Nov 23, 2015 at 14:33
  • Also, I have a RasPi running on this network, so bash scripts are an option. I have an SSHd running on my PC1, so I can SSH commands to it.
    – Daniel
    Commented Nov 23, 2015 at 14:33
  • I am not familiar with bash scripting so i can't help you out with a bash script.
    – doenoe
    Commented Nov 23, 2015 at 15:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .