Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: writing a utility to determine whether I have a working wifi connection

by Discipulus (Canon)
on Jul 26, 2019 at 08:23 UTC ( [id://11103424]=note: print w/replies, xml ) Need Help??


in reply to writing a utility to determine whether I have a working wifi connection

Hello Aldebaran,

if you r program have to be portable you can have a bounch of modules handling this: X::Y::ConnectionInfo responsible to load X::Y::ConnectionInfo::Linux or X::Y::ConnectionInfo::Win32 based on the OS you are running on.

See File::Spec (useful to write portable programs) and its structure.

Under win32 you can consider to just parse the output of:

netsh interface show interface

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: writing a utility to determine whether I have a working wifi connection
by Aldebaran (Curate) on Aug 08, 2019 at 23:32 UTC

    I ended up having so much trouble with the machine that I started this thread with that I went out and bought another. I was able to test whether I had wifi using perl, as kind of a first useful thing to do with a new windows machine. I'm not done looking at this issue, but I can now test it from another platform as well.

    C:\Users\tblaz\Documents\meditations>cd C:\Users\tblaz\Documents\meditations C:\Users\tblaz\Documents\meditations>perl 1.lwp.pl execution here execution there C:\Users\tblaz\Documents\meditations>type 1.lwp.pl #!/usr/bin/perl use 5.016; use warnings; use LWP::Online 'online'; say "execution here"; # "Is the internet working?" die "NO INTARWWEB!!!" unless online(); say "execution there"; __END__ C:\Users\tblaz\Documents\meditations>

    This seems to confirm the following.

    C:\Users\tblaz\Documents\meditations>netsh interface show interface Admin State State Type Interface Name ---------------------------------------------------------------------- +--- Enabled Connected Dedicated Wi-Fi C:\Users\tblaz\Documents\meditations>
    if you r program have to be portable you can have a bounch of modules handling this: X::Y::ConnectionInfo responsible to load X::Y::ConnectionInfo::Linux or X::Y::ConnectionInfo::Win32 based on the OS you are running on.

    Can you say a few more words about how to create this namespace?

    Again, thx all for comments,

      "Can you say a few more words about how to create this namespace?"

      I believe that Discipulus was using that namespace as an example, but either way, here's how.

      Using Module::Starter. I've left in all of the commands so you can see what's happening:

      spek@scelia ~/scratch $ module-starter --module=X::Y::ConnectInfo::Win +32 --author="Your Name" --email=your@email.com --license=perl Added to MANIFEST: Changes Added to MANIFEST: ignore.txt Added to MANIFEST: lib/X/Y/ConnectInfo/Win32.pm Added to MANIFEST: Makefile.PL Added to MANIFEST: MANIFEST Added to MANIFEST: README Added to MANIFEST: t/00-load.t Added to MANIFEST: t/manifest.t Added to MANIFEST: t/pod-coverage.t Added to MANIFEST: t/pod.t Added to MANIFEST: xt/boilerplate.t Created starter directories and files spek@scelia ~/scratch $ cd X-Y-ConnectInfo-Win32/ spek@scelia ~/scratch/X-Y-ConnectInfo-Win32 $ ll lib/X/Y/ConnectInfo/ total 20 drwxr-xr-x 2 spek spek 4096 Aug 9 13:57 ./ drwxr-xr-x 3 spek spek 4096 Aug 9 13:57 ../ -rw-r--r-- 1 spek spek 1989 Aug 9 13:57 Win32.pm

      By hand is the same. Create any directory to hold the distribution which is your top(root)-level directory (I typically name mine lower-case with dashes, eg: top-container-thing), which contains all of your distribution information and directory hierarchy. To have X::Y::ConnectInfo::Win32, we'd then create a lib directory (after going into your top-level dir), then an X directory in that, a Y directory within X, another directory... you get the picture. The magic happens at the Win32.pm file. That's what gets registered in @INC. That's how a module is brought to life.

      All that also means, that if you create, then drop a Ubuntu.pm file within the lib/X/Y/ConnectInfo directory, it'll be registered by the system as X::Y::ConnectInfo::Ubuntu module, ready for use. It'll be seen the same on the CPAN.

      One last note... when we say "module", we mean the actual code rendered out of the .pm file. We refer to the entire package of all the stuff shown above as the module's "distribution". We install distributions from the CPAN, and a distribution can include one, or several modules.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11103424]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-16 20:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found