how to set a proxy for python email client [closed] - python

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Recently I am studying email-related and have written a simple mail client to send emails.
But unfortunately due to the bad network I can not connect to smtp.gmail.com home. It is OK when I use a proxy in the browser, also OK when the script is run in company.
So are there any methods to set a proxy for smtp protocol? I don't see anything I can use in the smtplib module in Python2.7. And I think it is of no use to set the http proxy. They are two kinds of protocols. I have also searched Google and stackoverflow and can not find a reasonable resolution.
So, it seems there is a socket proxy. Is that useful?
Hope somebody could tell me something.

Install a local mail server which maintains its own mail queue like Postfix. Your own, local mail server actually is a caching SMTP-proxy, so exactly what you want to do. Your local application will deliver its mail to Postfix which makes sure the mail gets delivered to the actual recipient. There are lots of other mail servers doing this job totally fine, too.
Setting up Postfix is out of scope for an SO-Answer (or ServerFault, I guess it gets migrated), but there are lots of tutorials round there (and it depends on the machine you're using). Setting up postfix to use Gmail as smarthost will be of interest for you, too, as it involves some smaller hassles with certificates.

Related

SSL/TLS find Insecure Connection in VPN Project [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed yesterday.
Improve this question
I write a custom vpn project in python using TUN/TAP interface and UDP Socket connection for my self, and its work fine and every data that comes from the tun will encrypt and will goes through the udp connection securly and in server side comes from UDP and its decrypt and then sends to TUN interface.
in both side ethernet NAT with the TUN and in client its connect to my local.
All Pings transfer completely and all NAT works fine in server and client.
but when i want to open a google website or other websites, browser says ssl/tls insecure connection.
how it can findout this? and whats the way to solve this?
I test the websites from deferent computer in my local network and its not my browser or clock problem.
I know it is the problem of my project or NAT rules, but i dont know where it is?
I test my connection and NAT rulse and all of them works fine, and ping the google website through the VPN transfer completly.
I can ping everywhere but i cannot open any website because of ssl/tls insecure connection.

What is the best way to give a Linux command from one machine to a different machine? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I have a Django project on my laptop. It works perfectly fine on my machine.
This web app takes input from the user in the form of an image and reads the content in it. If the content is already present on the database, it runs a Linux command on a different machine. Both machines are connected to the same network.
Currently, I am using SSH to connect to the other machine but it asks for password every time. Is there any way I can eliminate the need for entering a password every time I want to run a command?
Solution 1: use SSH pre-shared key to login via SSH without a password. See this link for how to do it. After you have configured it properly, you are able to run a command on your server:
ssh hostname-or-ip-of-the-raspi command arg1 arg2 ...
and will execute command arg1 arg2 ... on the Raspberry PI, without being prompted for a password.
Solution 2: use TCP communication, and write a server for the Raspberry PI and a client for your server. You can use raw sockets, or some high level library such as zmq.
I am considering you are a simple intermediate programmer and based on that giving you two solutions with their pros and cons.
Solution 1: Using a simple Flask app on Raspberry PI
You can modify the following code to request a simple app running on PI to perform any actions.
Code:
from flask import Flask
app = Flask(__name__)
#app.route('/runMotor')
def hello_world():
runMotor()
# Run any script here
return "Motor Ran"
You can then use your raspberry to call something like:
<your_rasp_ip>:<port>/runMotor
Pros: Easy to implement, You can even move it further to be used from outside your firewall.
Cons: Slow and would not be suitable for very rapid concurrent request. Concurrency is the downfall (or you can queue the requests and then keep a check for this issue)
Solution 2 Using MQTT: MQTT is a machine-to-machine (M2M)/"Internet of Things" connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport.
You can play with your code, checkout example here
Pros: Extremely lightweight and removes concurrency overhead, MQTT is an asynchronous messaging protocol. This is best used for real time systems.
Cons: MQTT is a very light messaging protocol and cannot support heavy payloads.

How to make a port forward rule in Python 3 in windows? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Purpose:
I'm making a program that will set up a dedicated server (software made by game devs) for a game with minimal effort. One common step in making the server functional is port forwarding by making a port forward rule on a router.
Me and my friends have been port forwarding through conventional means for many years with mixed results. As such I am hoping to build a function that will forward a port on a router when given the internal ip of the router, the internal ip of the current computer,the port and the protocol. I have looked for solutions for similar problems, but I found the solutions difficult to understand since i'm not really familiar with the socket module. I would prefer not to use any programs that are not generally installed on windows since I plan to have this function work on systems other than my own.
Approaches I have explored:
Creating a bat file that issues commands by means of netsh, then running the bat.
Making additions to the settings in a router found under Network -> Network Infrastructure (I do not know how to access these settings programmaticly).
(I'm aware programs such as GameRanger do this)
Using the Socket Module.
If anyone can shed some light how I can accomplish any of the above approaches or give me some insight on how I can approach this problem another way I would greatly appreciate it.
Thank you.
Edit: Purpose
You should read first some sort of informations about UPnP (Router Port-Forwarding) and that it's normally disabled.
Dependent of your needs, you could also try a look at ssh reverse tunnels and at ssh at all, as it can solve many problems.
But you will see that working with windows and things like adavanced network things is a bad idea.
At least you should use cygwin.
And when you really interessted in network traffic at all, wireshark should be installed.
I'm not sure if that's possible, as much as I know, ports aren't actually a thing their just some abstraction convention made by protocols today and supported by your operating system that allows you to have multiple connections per one machine,
now sockets are basically some object provided to you by the operating system that implements some protocol stack and allows you to communicate with other systems, the API provides you some very nice API called the socket API which allows you use it's functionality in order to communicate with other computers, Port forwarding is not an actual thing, it just means that when the operating system of the router when receiving incoming packets that are destined to some port it will drop them if the port is not open, think of your router as some bouncer or doorman, standing in the entrance of a building, the building is your LAN, your apartment is your machine and rooms within your apartment are ports, some package or mail arrives to your doorman under the port X, a port rule means on IP Y and Port X of the router -> forward to IP Z and port A of some computer within the LAN ( provides and implements the NAT/PAT ) so what happens if we'll go back to my analogy is something such as this: doorman receives mail destined to some port, and checks if that port is open, if not it drops the mail if it is it allows it to go to some room within some apartment.. (sounds complex I know apologize) my point is, every router chooses to implement port rules or port blocking a little bit different and there is no standard protocol for doing, socket is some object that allows you program to communicate with others, you could create some server - client with sockets but that means that you'll need to create or program your router, and I'm not sure if that's possible,
what you COULD do is:
every router provides some http client ( web client ) that is used to create and forward ports, maybe if you read about your router you could get access to that client and write some python http script that forwards ports automatically
another point I've forgot is that you need to make sure you're own firewall isn't blocking ports, but there's no need for sockets / python to do so, just manually config it

WebSockets best practice for connecting an external application to push data [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am trying to understand how to use websockets correctly and seem to be missing some fundamental part of the puzzle.
Say I have a website with 3 different pages:
newsfeed1.html
newsfeed2.html
newsfeed3.html
When a user goes to one of those pages they get a feed specific to the page, ie newsfeed1.html = sport, newsfeed2.html = world news etc.
There is a CoreApplication.py that does all the handling of getting data and parsing etc.
Then there is a WebSocketServer.py, using say Autobahn.
All the examples I have looked at, and that is alot, only seem to react to a message from the client (browser) within the WebSocketServer.py, think chat echo examples. So a client browser sends a chat message and it is echoed back or broadcast to all connected client browsers.
What I am trying to figure out is given the following two components:
CoreApplication.py
WebSocketServer.py
How to best make CoreApplication.py communicate with WebSocketServer.py for the purpose of sending messages to connected users.
Normally should CoreApplication.py simply send command messages to the WebSocketServer.py as a client. For example like this:
CoreApplication.py -> Connects to WebServerSocket.py as a normal client -> sends a Json command message (like broadcast message X to all users || send message Y to specific remote client) -> WebSocketServer.py determines how to process the incoming message dependant on which client is connected to which feed and sends to according remote client browsers.
OR, should CoreApplication.py connect programatically with WebSocketServer.py? As I cannot seem to find any examples of being able to do this for example with Autobahn or other simple web sockets as once the WebSocketServer is instantiated it seems to run in a loop and does not accept external sendMessage requests?
So to sum up the question: What is the best practice? To simply make CoreApplication.py interact with WebSocketServer.py as a client (with special command data) or for CoreApplication.py to use an already running instance of WebSocketServer.py (both of which are on the same machine) through some more direct method to directly sendMessages without having to make a full websocket connection first to the WebSocketServer.py server?
It depends on your software design, if you decide the logic from WebSocketServer.px and CoreApplication.py belongs together, merge it.
If not, you need some kind of inter process communication (ipc).
You can use websockets for this ipc, but i would suggest, you use something simpler. For example, you can you json-rpc over tcp or unix domain to send control messages from CoreApplication.py to WebSocketServer.py

code to prevent DOS attack in python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a multi-client server code in which multiple clients are connected to a server.
Now all the clients are sending text messages to the server and are receiving a reply from the server. Now if one client tries to flood the server using a syn flood which the client runs in a different terminal then I want the server to close the connection of the client and the server still continues messaging with the other clients.
In short its how to prevent a DOS attack?
When dealing with a syn flood, you don't do that in Python. A syn flood is one machine sending a large amount of syn packages to your server, leading to an exhaustion of kernel resources.
The attack takes advantage of the fact that connection attempts are fully handled by the kernel. As such, your application will only get notified of a new connection after it was fully created (which will not happen in a syn-flood). Instead, your socket's backlog will quickly fill up and there will be no more connections attempts possible until the half-open connections time out.
As such, you'll have to handle this in the kernel, e.g. by increasing the socket's backlog (note that even half-open connections require some memory unless you use syn-cookies or similar) or by limiting the amount of syn-packets which are allowed to be received e.g. with iptables or other firewalls.
Generally, if the socket's backlog is full, no new connections will be accepted. Existing connections will not be affected by this and will continue to be served. Generally, when receiving a syn-flood, there are other kernel resources seriously strained which means, you might still have problems communicating depending on the actual circumstances.
To say it clear again: handling syn-floods is not a thing you'll be able to handle in Python but have to deal with by properly configuring your kernel.

Categories