LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Closed Thread
  Search this Thread
Old 10-09-2019, 06:41 AM   #1
P5music
Member
 
Registered: Nov 2010
Posts: 105

Rep: Reputation: 0
Translating Linux shell script to Windows10 MSDOS or Powershell


Hello,
I managed to create a Linux shell script that is able to switch between two different wifi services that very often hang but which can be manually reconnected with success.

Code:
while (true) do 

if ! [ "`ping -c 1 -W 1 www.google.it`" ]; then
    if (nmcli connection show --active | grep -c "FirstWiFi"); then
    nmcli connection up id "SecondWiFi"
   echo "switched to SecondWiFi"
   else
   nmcli connection up id "FirstWiFi"
   echo "switched to FirstWiFi"
   fi
fi

done
I am not suggesting to use this script because I do not know if it safe.

Now I need the same functionality on a Windows10 system.
I know that MSDOS shell is more limited than the bash shell or the like. But Windows10 has also Powershell.
As you can see the script is very simple so I think it can be translated. I do not know how to do it.
Maybe some easy suggestions can be found here.
Thank you in advance
 
Old 10-09-2019, 07:08 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 21,944

Rep: Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810
Quote:
Originally Posted by P5music View Post
Hello,
I managed to create a Linux shell script that is able to switch between two different wifi services that very often hang but which can be manually reconnected with success.
Code:
while (true) do 
if ! [ "`ping -c 1 -W 1 www.google.it`" ]; then
    if (nmcli connection show --active | grep -c "FirstWiFi"); then
    nmcli connection up id "SecondWiFi"
   echo "switched to SecondWiFi"
   else
   nmcli connection up id "FirstWiFi"
   echo "switched to FirstWiFi"
   fi
fi
done
I am not suggesting to use this script because I do not know if it safe.
How do you not know if it's safe?? You just said that YOU created it....don't you know what it does and how?
https://www.linuxquestions.org/quest...382/page2.html
Quote:
Now I need the same functionality on a Windows10 system.
I know that MSDOS shell is more limited than the bash shell or the like. But Windows10 has also Powershell. As you can see the script is very simple so I think it can be translated. I do not know how to do it. Maybe some easy suggestions can be found here.
Questions about Windows scripting would be much better on a Windows forum. While SOMEONE here may know an answer, you're far more likely to get help for Windows on a Windows forum. Much like your other thread where you didn't appear to look for any examples/samples, putting "windows powershell wifi script" into Google pulls up over 1.9 MILLION hits, with sample scripts and examples.

Start there.
 
Old 10-09-2019, 07:31 AM   #3
P5music
Member
 
Registered: Nov 2010
Posts: 105

Original Poster
Rep: Reputation: 0
@TB0ne

Safeness can be about the opportunity to have some script on the system in regard to performance or other issues, or about polling the network that way and so on.

Why do you answer questions when you have so poor technical knowledge?

We are all tired of you. No amusing at all anymore your histrionic and/or compulsive disorder.
Please reconsider subscribing to Quora to explain your experience.

Now I go writing on StackOverflow, please do not use your fake alias to answer me there or I will report you.
 
Old 10-09-2019, 07:39 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 21,944

Rep: Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810
Quote:
Originally Posted by P5music View Post
@TB0ne
Safeness can be about the opportunity to have some script on the system in regard to performance or other issues, or about polling the network that way and so on.
You wrote it; why don't you tell us what's unsafe about it then?
Quote:
Why do you answer questions when you have so poor technical knowledge?
If you say so.
Quote:
We are all tired of you. No amusing at all anymore your histrionic and/or compulsive disorder. Please reconsider subscribing to Quora to explain your experience. Now I go writing on StackOverflow, please do not use your fake alias to answer me there or I will report you.
Go wherever you'd like; if you think people are stalking you, seek help, as there's not much anyone on a technical forum can do for you.

AGAIN: you show no effort of your own, despite being told to numerous times. You post a script that you copied/pasted, and changed a small bit of and claimed it as your own, and now you want us to 'translate' the script to Windows for you. Again: 1.9+ million hits with examples for powershell wifi scripts...not sure how much more 'help' you need.

::EDIT:: And you continuing to come here for help is kind of ironic, considering you posted this (bolded pieces for emphasis only):
https://www.linuxquestions.org/quest...ml#post6040391

Quote:
Originally Posted by P5Music
To sum up, I am here to be helped, not to demonstrate my good will. Your help was very useful to me, so you have to decide whether to drop the false expectations and help me further as a gift.

Last edited by TB0ne; 10-09-2019 at 07:44 AM.
 
Old 10-09-2019, 08:18 AM   #5
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 2,652

Rep: Reputation: Disabled
Just to get back on point:
Quote:
Originally Posted by P5music View Post
Now I need the same functionality on a Windows10 system.
Surely, it would have made more sense to ask in a Windows forum, but anyway...

First, you need to obtain the "profile name" associated with each SSID. And what may that be, you ask? Just an identifier Windows uses; run netsh wlan show profiles to see. On my system, the "profile" name is identical to the SSID.

Now put your profile names and SSIDs in this cmd script:
Code:
@echo off

set wlanssid1=FirstWiFi
set wlanprofile1=ProbablyAlsoFirstWiFi

set wlanssid2=SecondWifi
set wlanprofile2=ProbablyAlsoSecondWiFi

rem *** the cmd version of a "while true" loop
for /l %%i in (0,0,0) do (
  ping -n 1 -w 1 www.google.it >nul
  if errorlevel 1 (
    set currentwlan=%wlanssid2%
    netsh wlan show interfaces | find " SSID" >nul
    if not errorlevel 1 (
       for /f "tokens=2 delims=:" %%b in ('netsh wlan show interfaces ^| find " SSID"') do set currentwlan=%%b
       set currentwlan=%currentwlan: =%
       netsh wlan disconnect >nul
       rem *** a pause is needed here, otherwise the connect
       rem *** operation below may fail
       ping -n 2 127.0.0.1 >nul
    )    
    if "%currentwlan%" == "%wlanssid1%" (
      netsh wlan connect ssid=%wlanssid2% name=%wlanprofile2% >nul
    )
    if "%currentwlan%" == "%wlanssid2%" (
      netsh wlan connect ssid=%wlanssid1% name=%wlanprofile1% >nul
    )
  )
  rem *** 5-ish second pause
  ping -n 6 127.0.0.1 >nul
)
Now, who said the Windows cmd shell was limited? (Actually I say that all the time, but it's still capable of performing quite advanced tasks.)

Note that if you have more than one WLAN interface in your computer, all the netsh commands require an extra "interface=" parameter.
 
2 members found this post helpful.
Old 10-09-2019, 08:40 AM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 21,944

Rep: Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810Reputation: 5810
Quote:
Originally Posted by Ser Olmy View Post
Just to get back on point:
Surely, it would have made more sense to ask in a Windows forum, but anyway...
OP was told that previously.
Quote:
First, you need to obtain the "profile name" associated with each SSID. And what may that be, you ask? Just an identifier Windows uses; run netsh wlan show profiles to see. On my system, the "profile" name is identical to the SSID. Now put your profile names and SSIDs in this cmd script:
Code:
@echo off

set wlanssid1=FirstWiFi
set wlanprofile1=ProbablyAlsoFirstWiFi

set wlanssid2=SecondWifi
set wlanprofile2=ProbablyAlsoSecondWiFi

rem *** the cmd version of a "while true" loop
for /l %%i in (0,0,0) do (
  ping -n 1 -w 1 www.google.it >nul
  if errorlevel 1 (
    set currentwlan=%wlanssid2%
    netsh wlan show interfaces | find " SSID" >nul
    if not errorlevel 1 (
       for /f "tokens=2 delims=:" %%b in ('netsh wlan show interfaces ^| find " SSID"') do set currentwlan=%%b
       set currentwlan=%currentwlan: =%
       netsh wlan disconnect >nul
       rem *** a pause is needed here, otherwise the connect
       rem *** operation below may fail
       ping -n 2 127.0.0.1 >nul
    )    
    if "%currentwlan%" == "%wlanssid1%" (
      netsh wlan connect ssid=%wlanssid2% name=%wlanprofile2% >nul
    )
    if "%currentwlan%" == "%wlanssid2%" (
      netsh wlan connect ssid=%wlanssid1% name=%wlanprofile1% >nul
    )
  )
  rem *** 5-ish second pause
  ping -n 6 127.0.0.1 >nul
)
Now, who said the Windows cmd shell was limited? (Actually I say that all the time, but it's still capable of performing quite advanced tasks.) Note that if you have more than one WLAN interface in your computer, all the netsh commands require an extra "interface=" parameter.
Yep...there are also TONS of sample scripts that do such things that the OP could have found (over 1.9 million, if they looked, the first one from Microsoft with a sample script), and based on their posting history, I was very reluctant to do their work for them.

This goes back to several of their previous threads, where they keep getting dropped from a free wifi connection...and their 'legal team' is going after them for 'fraud' (?). And whatever the situation, it has also been pointed out to them previously:
  • They DO NOT get dropped from their pay-for wifi connection
  • They DO get dropped from the free connection
They've been told that a well-managed network that supports a ton of users (like, say, a free public wifi?), has rules to prevent abuse. Sending a constant string of ping packets over and over, and instantly reconnecting from one to another over and over again, would most probably be the CAUSE of getting dropped. I've seen network rules that are far stricter than that, but they don't seem to take that into account.
 
Old 10-09-2019, 01:00 PM   #7
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,221
Blog Entries: 11

Rep: Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171
@P5music - This appears to be closely related to your other threads here and here. Duplicate threads are not allowed per the LQ Rules, but it will remain separate so long as the discussion is confined to that of the translation to a different shell language.

It would be helpful to others and thus, in keeping with the LQ guidelines if you could provide a little more information about why you think the script might be unsafe, and show any effort you have made at translating it.

Please review the Site FAQ for guidance in posting your questions and general forum usage. Especially, read the link in that page, How To Ask Questions The Smart Way. The more effort you put into understanding your problem and framing your questions, the better others can help!

Also, note in the above links, personal attacks on other members are not tolerated. Please review your posts in this thread and consider an edit where appropriate.

@everyone - Please keep this discussion strictly on topic - translation of this script to another shell language - and let it stand on its own merits without repeated references to other threads and past deeds.

Last edited by astrogeek; 10-09-2019 at 01:36 PM.
 
3 members found this post helpful.
Old 10-10-2019, 03:13 AM   #8
P5music
Member
 
Registered: Nov 2010
Posts: 105

Original Poster
Rep: Reputation: 0
@astrogeek
Rules are applied at convenience here, I do not think it is possible to use this old fashioned website with trolls ruling every thread.
Your intervention is very late and it was me to be repeatedly harassed. If you are accustomed to other badly-behaving members should not be a moderator. Please consider quitting.

Last edited by P5music; 10-10-2019 at 04:42 AM.
 
Old 10-10-2019, 11:17 AM   #9
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.6
Posts: 3,778

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
Quote:
Originally Posted by P5music View Post
@astrogeek
Rules are applied at convenience here, I do not think it is possible to use this old fashioned website with trolls ruling every thread.
Your intervention is very late and it was me to be repeatedly harassed. If you are accustomed to other badly-behaving members should not be a moderator. Please consider quitting.
This ad hominem post has been reported.

To the subject of the thread: One does not "translate" a (assumed) bash script to Windows, one just has to re-write it.
As suggested, perhaps you need to seek help on a Windows or PowerShell forum. I suspect you won't get any further help here.

Last edited by scasey; 10-10-2019 at 12:01 PM.
 
2 members found this post helpful.
Old 10-10-2019, 11:52 AM   #10
jeremy
root
 
Registered: Jun 2000
Distribution: Debian, Red Hat, Slackware, Fedora, Ubuntu
Posts: 13,020

Rep: Reputation: 3748Reputation: 3748Reputation: 3748Reputation: 3748Reputation: 3748Reputation: 3748Reputation: 3748Reputation: 3748Reputation: 3748Reputation: 3748Reputation: 3748
P5music,

As the LQ Rules note, "We are proud of the fact that despite of our growing numbers we continue to remain extremely friendly to both the newbie and the expert". This applies to all members. Please keep this in mind if you'd like to continue participating here.

--jeremy
 
1 members found this post helpful.
Old 10-10-2019, 12:07 PM   #11
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,221
Blog Entries: 11

Rep: Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171Reputation: 3171
@P5music - Please review the Site FAQ and LQ Rules for guidance in acceptable use of these forums.

From the LQ Rules:

Quote:
* Do not post any messages that are obscene, vulgar, sexually-orientated, hateful, threatening, hostile or insulting.
* Personal attacks on others will not be tolerated.
If you have other questions not answered in those links please contact us through contact links available on any page, or post to the Suggestions and Feedback forum.

If you have a complaint about another member's behavior, or want to dispute a moderator's decisions, the proper action is to use the Report button at bottom of the offending post to ask for a review. Resort to name calling and insults is not acceptable.

I specifically asked...

Quote:
Originally Posted by astrogeek View Post
@everyone - Please keep this discussion strictly on topic - translation of this script to another shell language - and let it stand on its own merits without repeated references to other threads and past deeds.
As you have chosen to ignore that request, this thread is now closed.

Last edited by astrogeek; 10-10-2019 at 12:11 PM.
 
2 members found this post helpful.
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Duel boot windows10/Linux 19 cinnamon. Linux not completing boot. tigtags Linux - Laptop and Netbook 8 08-22-2018 06:31 PM
LXer: Microsoft open-sources PowerShell for Linux, Macs. Repeat, Microsoft open-sources PowerShell for Linux LXer Syndicated Linux News 0 08-19-2016 03:50 AM
dual booting windows10 and arc linux abhishek021 Arch 3 09-26-2015 05:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration