Browse Source

Allow binding TCP socket to interface by passing 'iface' arg. Linux only.

master
Dmitry Ermakov 1 year ago
parent
commit
a9603ec450
  1. 6
      dvrip.py

6
dvrip.py

@ -4,7 +4,7 @@ import json
from time import sleep from time import sleep
import hashlib import hashlib
import threading import threading
from socket import socket, AF_INET, SOCK_STREAM, SOCK_DGRAM from socket import socket, AF_INET, SOCK_STREAM, SOCK_DGRAM, SOL_SOCKET
from datetime import * from datetime import *
from re import compile from re import compile
import time import time
@ -100,6 +100,7 @@ class DVRIPCam(object):
def __init__(self, ip, **kwargs): def __init__(self, ip, **kwargs):
self.logger = logging.getLogger(__name__) self.logger = logging.getLogger(__name__)
self.ip = ip self.ip = ip
self.iface = kwargs.get("iface", None)
self.user = kwargs.get("user", "admin") self.user = kwargs.get("user", "admin")
hash_pass = kwargs.get("hash_pass") hash_pass = kwargs.get("hash_pass")
self.hash_pass = kwargs.get( self.hash_pass = kwargs.get(
@ -130,6 +131,9 @@ class DVRIPCam(object):
self.socket_send = self.tcp_socket_send self.socket_send = self.tcp_socket_send
self.socket_recv = self.tcp_socket_recv self.socket_recv = self.tcp_socket_recv
self.socket = socket(AF_INET, SOCK_STREAM) self.socket = socket(AF_INET, SOCK_STREAM)
if self.iface:
self.socket.setsockopt(
SOL_SOCKET, 25, str(self.iface + '\0').encode())
self.socket.connect((self.ip, self.port)) self.socket.connect((self.ip, self.port))
elif self.proto == "udp": elif self.proto == "udp":
self.socket_send = self.udp_socket_send self.socket_send = self.udp_socket_send

Loading…
Cancel
Save