Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Read hostdomain over VPN

by Takamoto (Monk)
on Nov 16, 2020 at 14:45 UTC ( [id://11123689]=perlquestion: print w/replies, xml ) Need Help??

Takamoto has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks

For a desktop application of mine, I need to read the hostdomain of the net where the application is running. I do this with

use Net::Domain qw(hostdomain hostfqdn); my $hostfqdn = hostfqdn; print "FQDN : $hostfqdn \n"; my $hostdomain = hostdomain; print "DOMAIN: $hostdomain \n";

This works fine for most of my scenarios, but when the user is connected to an (enterprise) VPN. In this base 'hostdomain' returns empty. Is there a way to get a similar response 'as if' the computer was in the physical net? What I am trying to achieve is to determine in which company the tool is run to enable certain functions, and I need to do it so not only when the tool is run in a computer which is physically in the company (working fine), but because of many users working from home nowadays also on a computer connected by VPN to that company.

Replies are listed 'Best First'.
Re: Read hostdomain over VPN
by pryrt (Abbot) on Nov 16, 2020 at 15:18 UTC
    I don't have a solution/implementation to the exact request that you made, but do have a couple high-level comments:

    It seems to me that relying on internal hostdomain settings to get access to the right functions for the tool is fraught with danger: all it takes is for one user to know that this is how you enable a given featureset, and if he can figure out the hostdomain for a company that's paid you more $$$ to get more features activated, he may then spoof being from that other company, and get extra features for free.

    I would think a better way would be to give each company unique license files, and have the application transmit some identifier based on the license file when it's talking with the server (maybe using Public Key Authentication), and have the server only activate the features when given a license key that has those features available.

      Hi Pryrt

      Thank you for your comment. I agree with you and this is the way most features/license control is done in my application. But for a specific set of features, I need to assure (or try to the best degree I can) that the tool is only used inside the company (physically) or - because of the new normal 'home office' - or with a computer connected to a company VPN. Of course, this limitation can be overcome with only a bit of knowledge, but for my 'low-level requirements' would do the job. So anything that could read - in Perl - some info from the VPN, would work for my case.

Re: Read hostdomain over VPN
by Bod (Parson) on Nov 16, 2020 at 18:27 UTC

    In the past...quite long past...I had a similar issue with VPN.

    After lots of head scratching and pondering, it turned out that it was actually a DNS issue. The remote user was successfully connecting over VPN but using the DNS server of their home ISP.

      Thank you Bod. This is interesting, indeed. I have been able to reproduce this on my computer. I connect to the VPN of my employers, and my method in the code above returns empty; however, running a check in the browser with a tool such as https://www.ipqualityscore.com I get back IP and DNS correctly. Would this scenario apply to the experience you described?

        Since you can create this scenario just monitor your own connection to find out exactly what goes where. See Wireshark. This isn't a perl problem.

        I don't recall pointing a browser at the problem Takamoto. Probably the investigations were limited to Windows command line tools...
        I remember the sleepless nights of waking up with an idea and jumping out of bed to try it...

        The bizarre things we did when we were young and silly...or is that just me?

Re: Read hostdomain over VPN
by jszinger (Scribe) on Nov 16, 2020 at 21:42 UTC

    On my work laptop perl -MNet::Domain -E'say Net::Domain::hostfqdn returns 'example.lan' on my home network and nothing when connected to work’s VPN. Not surpising, since they don’t provide a DNS entry for the VPN connection.

    Also, what should happen if a worker tries to use the program when disconnect from the VPN?

Re: Read hostdomain over VPN
by Takamoto (Monk) on Nov 16, 2020 at 20:59 UTC

    The following is my partial solution to get the VPN information:

    use Sys::Hostname::FQDN qw(asciihostinfo); my ($name,$aliases,$addrtype,$length,@addrs)=asciihostinfo(); print "Local IP:" . $addrs[0] . "\n"; print "VPN IP:" . $addrs[1] . "\n";

    On my test machine it provides correctly the IP of the VPN. To get more information, I could call some API on the web but IP should suffice."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11123689]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-25 08:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found