?
Solved

How to create a Python Rest API call to Firewall for url filtering

Posted on 2014-01-03
3
Medium Priority
?
867 Views
Last Modified: 2014-02-11
Hi Guys,

I'm new to Python but i really want to figure out how to implement this solution in a desktop or preferably Python web GUI. I need to create a simple Python GUI application that will tap into my Firewall's API which I already have. The GUI will have a simple line to enter a url that needs to be blocked. Once the user enters it they press enter and the api below is executed: for a site named www.badsite.com

http(s)://hostname/api/?type=config&action=set&xpath=/config/devices/entry/vsys/entry[@name='vsys1']/pro files/url-filtering/entry[@name='xml test']/block-list&element=<member>www.badsite.com</member>

How would I get this into a GUI and how can I call the API?

I'm familiar with bash and with it I can get user input like

What is the site to be blocked?
get input
block = badsite2.bad.com

Then I can append block as a variable into the API call as seen below:

http(s)://hostname/api/?type=config&action=set&xpath=/config/devices/entry/vsys/entry[@name='vsys1']/pro files/url-filtering/entry[@name='xml test']/block-list&element=<member>$Block</member>

I want the http post to be executed when the user presses the "enter button" Here is what I'm thinking.

import urllib2
import urlparse

Block_url = raw_input("Enter URL to be blocked: ")

url = "http(s)://hostname/api/?type=config&action=set&xpath=/config/devices/entry/vsys/entry[@name='vsys1']/pro files/url-filtering/entry[@name='xml test']/block-list&element=<member> + Block_url </member>"
try:
  result = urllib2.urlopen(url)
except urllib2.URLError, e:
  handleError(e)

Open in new window

0
Comment
Question by:Tbalz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Expert Comment

by:Walter Ritzel
ID: 39788840
That is pretty much what you need. So, you can probably close this question with no points distributed.

Tks,
Walter.
0
 

Accepted Solution

by:
Tbalz earned 0 total points
ID: 39841052
guess i answered my own question
0
 

Author Closing Comment

by:Tbalz
ID: 39849697
No one could figure it out
0

Featured Post

Ransomware Attacks Keeping You Up at Night?

Will your organization be ransomware's next victim?  The good news is that these attacks are predicable and therefore preventable. Learn more about how you can  stop a ransomware attacks before encryption takes place with our Ransomware Prevention Kit!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
Sequence is something that used to store data in it in very simple words. Let us just create a list first. To create a list first of all we need to give a name to our list which I have taken as “COURSE” followed by equals sign and finally enclosed …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question