Can I run Python 2.7 Libraries (Impacket, Pcapy) on Django - python

Hi I just want to ask if its possible to run Impacket to Django,
On my project I am already done on my sniffing and parsing using Impacket and Pcapy but my clients requested that the GUI will be web based. I picked Django because its the most widely used and all but I am having doubts that it can run my Libraries.
For starters can Django open my NIC in Ubuntu and have access to sniff on it?
or is it better for me to use Flask for from what I read flask is being run on the Python Console Application, from what I understood I will install a HTTP Server in the Project then the Python Console will be like a Controller (MVC) to my GUI which is Flask.

You can run anything from Django, it just provides a framework to get stuff to the web.
As long as the Django application is running as a user which has privileges to access your NIC there won't be an issue with that.
You can simply call your code you already have from the Django Views.
The time this stuff takes may be too long for a web request so you may need to pass some stuff down a message queue and look up the results. Look at Celery for that purpose.
I do prefer Flask over Django but it doesn't matter what you use.
Just remember Django is another library it all still runs inside Python :)

Related

Django Server inside another program

I wrote a Django app that collects data from clients and displays them in it's web app.
Now I want to write a script/program (WPF or a small Java App) that manages the Django server. Things like Start/Stop, update Django files, migrate Data etc.
Reason is: I want to stuff all of that into an .exe, maybe with a setup and licensing for my potential customers.
What would be the most professional attempt to do this? I wrote smaller scripts before and built them with pyInstaller, which does not seem to work with Django. Or should I just install a python interpreter with my setup and just run the python files? Then my code would be visible to my customers.
Any tips are appreciated.
you have two options really. either run the app on the customer's hardware or your own. if you don't want your code exposed you should consider hosting the application yourself and providing them with authentication
Django authentication is actually pretty robust, check out these two articles from the official docs. This is a general tutoria on authentication l: docs.djangoproject.com/en/2.0/topics/auth/customizing/… and this is a broader scope one on django in general docs.djangoproject.com/en/2.0/intro/tutorial01
Edit: just do it here

Need advice on how to incorporate Python into an Azure, specifically an ASP.NET web application environment

Need advice on how to incorporate Python into an Azure ASP.NET web application environment. Please excuse this question but I am new to Azure and I'm not clear on how to proceed. Every option that I look into looks promising but they all seem to have their own issues. Below is a more thorough explanation but the deal is that I have an Azure account with all kinds of goodies, a full fledged ASP.NET (C#) web app running via App Service, I am new to Azure (but not Python), and I'm hoping to add Python functionality to this whole setup. In short:
I want to add Python to this setup mainly to run scheduled jobs and also to trigger Python code from ASP.NET web form submissions
ideally I want a solution that resembles a non-cloud setup. I know this sounds silly but I'm finding the cloud/Azure functionality to be nuanced and not straightforward. I want a place to put a bunch of Python scripts, run, edit, schedule and trigger them from ASP.NET
for example: I created a WebJob that runs manually and from the documentation it wasn't clear how it should be called. I just figured out that you need to POST with Basic Auth (and the credentials provided).
!Also, Azure CMD does NOT like files with 'underscore _' in them! You cannot submit a Web Job with a py file with an underscore nor can you write output with a file with an underscore
!Also, I don't see an option for this Web Job to run Python 3.6.4 (which I installed via extension). Right now it is using 2.7.15...
!Also, CRON expression in Azure has six *, not five plus a command. Again, more weird stuff to worry about
I tried these instructions but the updates to the web page's Web.config file breaks the ASP.NET web pages
ideally the most cost effective option
Any info is greatly appreciated
MORE DETAILED EXPLANATION
Currently I have an ASP.NET site running via Azure App Service and I would like to add Python scripts and possibly Flask/Rest functionality. Note that I am not expecting to serve any content via Python and will largely be running Python scripts either on a scheduled basis or call them from ASP.NET. As a matter of fact, and this is an important point, I'm hoping to have ASP.NET trigger/run a Python script when a web form is submitted. I realize that I could get a similar effect if I make a web call to a Rest api that is running Python. In any event, I can't tell if I should:
add a Python extension to the current App Service running the web page (I tried this) OR
I did install Python 3.6.4 and some packages via pip
These instructions were useful, however the updates to the web page's Web.config file breaks the ASP.NET web pages
set up a VM that will have all of the Python code (but how can I have the .NET web page(s) call the Python in the VM?) OR
use Azure functions (I'm completely new to this and must admit that I prefer to have my old school Python environment instead although I see the benefit of using functions. But how do you deal with logging and debugging?)
or what about a custom windows container (Docker)?
This requires installing VS Code and that is OK but I'm looking for a solution that another user can get into with as few interruptions as possible
The idea is to ramp up the use of Python although, like I said, I don't expect Python to be serving any of the web content. It will be used to run in the background and to run scheduled jobs. What is the most robust and hopefully easiest way to add Python functionality to Azure (most importantly in a way to be able to trigger/use Python from an App Service running .NET?)? I've searched online and stack overflow so far with interesting finds but nothing to my liking.
For example, the following link discusses how to schedule WebJobs. I just created a manual one and when I called the webhook I got the message: "No route registered for '/api/triggeredwebjobs/TestPython/run'" How to schedule python web jobs on azure
The Docker method looks very promising, however, I'm looking for a simple solution as there is another person who will be involved in all of this and he's busy with other projects
Thank you very much!
I found a solution, though I'm open to more info. Like I mentioned in my post, I used the 'add extension' tool to add Python 3.6.4 to my Azure (installed in D:\home\python364x64).
Then I installed a bunch of packages via pip, these installed into D:\home\python364x64\Lib\site-packages.
I created a Python folder in webpages\Python where I put my scripts.
Finally, in ASP.NET I used the Diagnostics.Process call to run my code in ~\webpages\Python\somecode_2.py
The main issue is that Azure came with Python 2.7.15 installed. And for some reason when my Python code got executed it was using 3.4 (where that version came from beats me). So for each script, I had to create an _2.py version where I simply did the following in order to call the original script via Python 3.6.4. Looks a little nasty but it works. So like I said, I would welcome more info for ways to do this better...
--
import os<br>
os.system("D:\\home\python364x64\python.exe SomePython.py {0}".format(add arguments here)

Can the Pyramid framework be run on a CGI server

Ok, I get that CGI is sow outdated, and no one likes it, but I have a customer who needs a new site, is on shared hosting, and does not wish to change hosting providers. We are doing the back-end of his site in Python, and are researching Python framework options that can run as CGI(no one wants to just use the CGI module). So far, It seems Django can be run on CGI, but it is terrible. Flask and Bottle seem to run well on CGI(at least it is supported), but I was wondering if the Pyramid Framework can. If not, I guess we will just be using Flask. Can I get Pyramid running on CGI? If so what would be the performance against running Flask r Bottle under CGI?
See this solution here, it shows how to use WSGI on CGI
https://www.python.org/dev/peps/pep-0333/#the-server-gateway-side
Take a look at wsgiref as well
https://docs.python.org/2/library/wsgiref.html
example :
https://github.com/w1mvy/twitter_bot_on_gae-py/blob/55754d0ec1580b67f7f0c710f5cf3456313cff4d/app.py

How to use scripts to excecute django commands

Hi recently created my website in django. And I have used a web hosting provider who has django, python and my sql installed. But they do not have the ssh option or command prompt in their file manager. How can I use a script to excecute all the commands after uploading my site to the server .
I want file to be created like this updatedb.sh or updatedb.py .
Can anyone tell me how to use the scripts alone to host my django site live.
It is possible to have your Django views execute lines like:
import os
os.system("python manage.py syncdb")
In theory you could get the site working like that. However, this is a very poor strategy for deployment. Aside from the hassle of having os.system lines every time you want to do anything, what will you do if your entire site breaks? You'd be using convoluted hacks just to do the most basic maintenance.
If your web hosting provider truly doesn't support any kind of command line or even give you other options for setting up Django, it's time to find a new web hosting provider. I might recommend heroku, which supports Django and lets you deploy using git. (It is also free up to a certain amount of use).

Simple python mvc framework

Is there any lightweight mvc webframework which is not necessary to install to the server?
I need something simple, that i could just copy to the shared hosting. And it must handle urls other that localhost/test.py, something like this localhost/Blog/test
You should probably check out Flask or Bottle, two nice Python microframeworks. With an appropriate "main" Python script (to initialize your app and dispatch requests to it) and mod_rewrite rules in place, you can probably get pretty close to your goal of "just copy[ing] to the shared hosting" with nice URLs.
Flask has good documentation on deploying via CGI, which is what you might have to use on your shared host. (If your host supports FastCGI or mod_wsgi, those deployment options would be preferable.)
Checkout web2py. Seems to be about the simplest python based webserver I can think of.
Django might do, it's hefty, but it comes with it's own development server.
web2py includes everything (ssl-enabled web server, sqlite sql based transaction safe database, web based Integrated Development Enviroment, web based database interface) in one package. The web2py binaries for windows and mac also include Python itself. web2py does not require configuration or installation and can run off a usb drive. It was originally developed as a teaching tool for MVC.
checkout https://github.com/salimane/bottle-mvc or https://github.com/salimane/flask-mvc . They are boilerplates that could get you started with controllers, models in separate folders. They are based on bottle and flask micro frameworks, no useless features, they give you the flexibility to plugin whatever modules you want.

Categories