Unable to discovring Camera with different 3rd Octet part of IP - python-3.x

I'm looking for discovering the IP cameras that are connected to my network. I found a tool in the following link
https://github.com/andreikop/python-ws-discovery
when I'm using it with the following commands I can not find one of my cameras which is in my network
from wsdiscovery.discovery import ThreadedWSDiscovery as WSDiscovery
from wsdiscovery.publishing import ThreadedWSPublishing as WSPublishing
from wsdiscovery import QName, Scope
# Define type, scope & address of service
ttype1 = QName("http://www.onvif.org/ver10/device/wsdl", "Device")
scope1 = Scope("onvif://www.onvif.org/Model")
xAddr1 = "localhost:8080/abc"
# Publish the service
wsp = WSPublishing()
wsp.start()
wsp.publishService(types=[ttype1], scopes=[scope1], xAddrs=[xAddr1])
# Discover it (along with any other service out there)
wsd = WSDiscovery()
wsd.start()
services = wsd.searchServices()
for service in services:
print(service.getEPR() + ":" + service.getXAddrs()[0])
wsd.stop()
the result of this commands are:
urn:uuid:9b8cd29b-4bd4-5d1c-2f0c-edf3ff9a7eb3:http://#.#.42.244:80/onvif/device_service
urn:uuid:c65e3f71-99e5-4c5d-9615-325bcab19840:http://#.#.42.128/onvif/device_service
urn:uuid:317435e5-a21c-467b-96b8-a213e455bcb4:http://#.#.42.60:5357/317435e5-a21c-467b-96b8-a213e455bcb4/
my own IP is #.#.42.53
and two IP cameras with IPs:
#.#.42.244 and #.#.42.128 are discovered
but I have another camera which IP is #.#.5.179 and it isn't discoverd.
it's because that it has various IP range from my computer? (the camera range is 5 and my computer range is 42)
In that case how I can solve this problem and expand my discovery range?

Related

Defining IP address to a programatically defined VLAN

I am trying to create TAP's programatically, to which i am attaching a VLAN and an IPV4 address.
(using C, linux 5.4.56, on an embedded device)
TAP is created correctly with the regular ioctl's (TUNSETIFF, etc ...)
Then, i am using another set of ioctl's to set the VLAN, IPADDR, NETMASK, FLAGS, etc ... (SIOCGIFFLAGS, SIOCSIFADDR, etc ...).
For example
init_sockaddr_in_str((struct sockaddr_in *) &ifr.ifr_addr, ipv4_addr_str);
if (ioctl(sd, SIOCSIFADDR, &ifr) < 0) {
LOG("ioctl(SIOCGSIFADDR) error: (%s)\n",strerror(errno));
}
for setting the IPaddress, sd being a socket created to access this interface file descriptor.
Let supposet I created tap256 at first, the a VLAN tag 256, and an IPaddress a.b.c.d
The problem i have is that, at linux cli, i can correctly see all these interfaces with
"ip -d a"
but
Only the TAP256 is UP with the address set to IT ... an no VLAN
Another interface has been created (TAP256.256) which is DOWN with the VLAN defined
Of course, i can fix this manually (removing the IP addr from one interface, setting it to the other, etc ... but this is not the preferred option, i really liked it to be done programatically.
Is there something i am doing not right ? or a specific sequence of actions which will lead to my TAP256.256 UP and the correct IP address attached to it ?
Thanks,
Jacques

Check if ip belongs to subnet in python3

I'm trying to check if a list of ip addresses (list called ips) belong to a list of subnets (list called subnets). If one ip from ips belong to subnet from subnets, it is considered as scanned. My goal is to find not scanned subnets.
I wrote this small script which seems to work, but the actual result is not accurate. What do I mean by saying that: it is accurately parses the subnets from a file (there are 100 subnets), but after the for executing it appears to miss some results, because in the end there are only 97 subnets. Any help will be appreciated.
Data looks like this:
ip adresses:
172.0.0.1
172.0.0.2
etc
subnets:
172.0.0.1/24
186.0.0.1/30
etc
the code fragment:
print(len(subnets)) #returns 100
for ip in ips:
for subnet in subnets:
if(ip in subnet):
scanned.append(subnet)
scanned = list(set(scanned))
notscanned = [x for x in subnets if x not in scanned]
print(len(scanned + notscanned)) #returns 97

Subnets to AZs and repeat

I want to build a 3 tier VPC using only AZ1a and AZ1b. But I want to have a range of IP addresses and use them for each tier but need them to always fall in AZ1a or AZ1b.
I have 3 app tiers (web, app, db):
Using only two AZs.
availability_zones = ["us-east-1a", "us-east-1b"]
I have put together a list of the subnets I want to use. SoI want web to grab the first two and put into each of the AZs, then I want app to grab the next two and put into each of the AZs, and so on on.
private_subnets_cidr_intapp = ["10.211.130.0/28", "10.211.130.16/28", "10.211.130.32", "10.211.130.48", "10.211.130.64/28", "10.211.130.80/28"]
How do you go about this, and an example would help. Should I be using a map?

python3,boto3,aws ec2 instance's second ip obtain

Somehow, I had to get second eth1 private ip address of ec2 instances using python3. I can get only ec2 instance-id. I managed to do it,but it is not good code I think.
I tried filters but failed. Instead I use like below.
ec2 = boto3.client('ec2')
def get_sec_ip(instance_id):
res=ec2.describe_instances(InstanceIds=[instance_id])
print(res['Reservations'][0]['Instances'][0]['NetworkInterfaces'][1]['PrivateIpAddress'])```
instance_id = 'i-03a0d15992b7bf'
get_sec_ip(instance_id)
Is there anybody who did this result using ec2.describe_instances' filters?
An other possibility is to use Instance object:
ec2 = boto3.resource('ec2')
instance = ec2.Instance(instance_id)
print(instance.network_interfaces[1].private_ip_address)
The filter is not used for limiting output, but limiting number of instance descriptions return. For example, the describe_instances can return 10 instances (not in your case, but in general), and Filters can limit it to only 2 based on some criteria, e.g. instances only in a given subnet.

Does DNSpython have a method that automatically performs a forward or reverse lookup depending on the value that it's passed?

I am wondering if there is a way to pass either a host, fqdn, or IP address to DNSPython and have it perform the proper lookup (forward for hosts and fqdns and reverse for ips). Also, I want to know what kind of address (host, fqdn, or ip) was sent to the method originally.
Thanks in advance
To my knowledge, there's not a single function that will do what you're looking for. However, it wouldn't be too hard to implement. Here's how I'd probably do it.
First, I'd check if the input was an IP address
import ipaddress
def is_ipaddress(string):
try:
ipaddress.ip_address(string)
return True
except ValueError:
return False
If it is an IP address, then I'd call dns.query.reverse_query(). This is assuming I have installed the latest development version of dnspython from Github because reverse_query() was only recently added (see https://github.com/rthalley/dnspython/commit/7c105cce64699e1a221176f98f7cb9e682aba1e0).
If it's not an IP address, then I'd prepare my query with dns.message.make_query(name, rdtype) and then send it with dns.query.udp().
If you wanted to use the value of search in /etc/reolv.conf, you might consider creating a dns.resolver.Resolver, which currently does search processing by default.
import dns.resolver
import dns.rdatatype
resolver = dns.resolver.Resolver()
response = resolver.query('my-computer', dns.rdatatype.A)

Resources