Checking NORDVPN through Make a Web Request


#21

@eibyer I had looked at ipify and if ipify was running on my LAN, I would be able to get my public address. Unfortunately, when I use Webcore to call Ipify, since Webcore code runs in the cloud, I get the public ip of the Webcore server.

Ideally it would be awesome if someone had written a web page that I could host on a web instance on my LAN that I could do an HTTP GET to from Webcore. I’ve searched everywhere and I have no idea how to code the HTML/JSON code needed to accomplish this.

I am now searching for a Docker image that might create a Web instance for this.


#22

I have a solution for you… Just tested and works fine to return external IP of a device on my lan (linux box).

On linux server:
python script:

ip.py:

#!/usr/bin/env python3
from requests import get
ip = get(‘https://api.ipify.org’).text
print(ip)

Then I’m running Flask to create an http endpoing to execute and return the results of ip.py
Flask config:
export FLASK_CONFIG=myip.py; flask run --host=<local_ip_of_linux_box>

myip.py:

from flask import Flask
import subprocess
app = Flask(__name__)

@app.route('/ip')
def my_ip():
    cmd = ["/root/FLASK/ip.py"]
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
    out,err = p.communicate()
    return out



if __name__ == "__main__" :
    app.run()

Now make a call from WC and it’ll store a var:

webcore

Note: You could also do this without Flask and code everything in myip.py and serve is under the apache root, just takes an extra few lines of python code and you’ll need to turn on ExecCGI in apache.conf:

<Directory /var/www/html>
	Options +ExecCGI
	AddHandler cgi-script .py
</Directory>

Edit: code formatting


#23

ALTERNATE SOLUTION USING APACHE:

apache.conf, enable execCGI stuff on DocumentRoot (or wherever you want to store scripts under the docroot):

<Directory /var/www/html>
	Options +ExecCGI
	AddHandler cgi-script .py
</Directory>

Now create the ip.py in the directory you have specified above:

ip.py:

#!/usr/bin/python3
# -*- coding: UTF-8 -*-# enable debugging
import cgitb
cgitb.enable()
print("Content-Type: text/html;charset=utf-8")
print()

from requests import get

ip = get('https://api.ipify.org').text
print(ip)

Now make your GET request in webcore to log $response:
http://<IP_of_Box>/ip.py

Edit: You’ll probably need to import the python libraries for “requests” and “cgitb”


#24

One more to play with, python also that you run from cron every so many minutes. Call a webcore piston which will give you $args.IP that you can process within WC.

from requests import get

ip = get('https://api.ipify.org').text
data = {'IP':ip}
get('https://graph.api.smartthings.com/api/token, params=data)

#25

@allrak The idea of running a Python script from a server on my LAN is very doable. I have a Raspi I can use or an Ubuntu Docker container that is running. I totally understand the Webcore piston. I’ve never done anything with Python scripting. So, I am an extreme NOOB there. I am not even sure if Python is installed on my Raspi.

You seem to be creating the ip.py script and then you are creating a myip.py script. I am not sure if I understand that. Is Flask another web server? Do I have to install it? I need a step by step to comprehend. LOL…see one, do one, teach one.


#26

Easiest way is to use my second post method where it strictly uses Apache (not Flask).
The advantage to just using apache to execute your script makes it way less complicated.

Would be pretty simple to it setup on a RP3.

apt-get update
apt-get install apache2
a2enmod cgi

Add the following to /etc/apache2/apache2.conf

<Directory /var/www/html>
	Options +ExecCGI
	AddHandler cgi-script .py
</Directory>

Restart apache:
service apache2 restart

Install pip to handle python package installs:
apt-get install python3-pip

Satisfy library dependencies your about to use in the new ip.py script:
pip3 install requests

Create /var/www/html/ip.py:

#!/usr/bin/python3
from requests import get
print("Content-Type: text/html;charset=utf-8")
print()
ip = get('https://api.ipify.org').text
print(ip)

Make the script executable:
chmod 755 /var/www/html/ip.py

Point your web browser to http://<your_rp3_ip>/ip.py

It should return a single item on the page… your external IP address.

Let me know if it works for ya!

Edit: *Added part about making the script executable (chmod 755)


#27

@allrak I tried this on my Docker image but I kept getting a DNS error trying to start Apache. So, I went to a Raspi that I have and followed your excellent guide. Everything seemed to work just fine. When I go to the http://172.16.1.15/ip.py on my Pi, I get a “You have chosen to open a text file”. When I do, it is a Zero byte file. I checked and verified that I performed all of your steps. Advice?


#28

The fourth time is the charm. I fixed a typo and now the http://172.16.1.15/ip.py opens just fine, but the resulting screen is blank. I don’t see an ip address or any text.


#29

@allrak Yay!!! It is working. IN your example, you needed to have specified:

ip = get(‘http://api.ipify.org’).text

and not HTTPS.

So, I have it returning the address in the browser. However, the HTTP GET call from the Webcore piston is coming back null. Any ideas?

image


#30

Right after the GET request, I would log to console or set string variable to $response to see exactly what webCoRE sees.

temp


#31

The response is null, but now when I go to the web page from browser it is also null. The web call from the browser actually only worked the first time I did it after creating the python script. Now it comes back null.


#32

@allrak I have thoroughly checked the code via your very helpful guide and although I got the web page to list the address once, now when I call http://172.16.1.15/ip.py, the page pauses for about five seconds and then never prints and no error either. Any further ideas?


#33

Can you execute the python script from the command line on your rp3 and paste the output?
example:
cd /var/www/html; ./ip.py


#34

@allrak Here is what I am getting…

image


#35

I guess I just answered my own question… I have “.txt” and not “.text”… forced habit in coding… duh, works now. Thx so much.


#36

So everything is working now? Piston is returning the the IP address in $response?


#37

Thank you. Finally success. Here’s the web page…
image

and here is the piston…
image


#38

Sorry for the delayed post, but for those who find this thread later, I created a piston to make a query to my router to determine my External IP. (No Windows or Raspberry Pi required)

I have not tested this with VPN yet, but if that IP is visible from the router’s config page, it should work for that as well. It is important to note that each router can be different, so it will take a bit of customization to work in your environment.


#39

@PhantomSpice @AvronW Did you get this going? Here’s probably the simplest way to check your ip address… A DTH from 2014 works well…