Monday, 27 November 2023

How to check if a port is opening?

$ nc -zv 192.168.1.123 4440
Connection to 192.168.1.123 4440 port [tcp/*] succeeded!
$ nc -zv 192.168.1.123 1234
^C

Thursday, 16 November 2023

How to write a video using gstreamer with opencv

import numpy as np
import cv2, os
gstcmd = "https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4" #cap = cv2.VideoCapture(gstcmd, cv2.CAP_GSTREAMER) cap = cv2.VideoCapture(gstcmd) count = 0 h = 1080 w = 1920 gst_out = "appsrc ! video/x-raw, format=BGR ! queue ! nvvideoconvert ! nvv4l2h264enc ! h264parse ! qtmux ! filesink location=/data/test.mp4" out= cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, 0, float(60), (int(1920), int(1080))) while(True): try: count += 1 # Capture frame-by-frame ret, frame = cap.read() if ret == False: break #frame = np.fromstring(frame, dtype=np.uint8).reshape((int(h*3/2),w,1)) #frame = cv2.cvtColor(frame, cv2.COLOR_YUV2BGR_NV12) print(frame.shape) out.write(frame) # Display the resulting frame #cv2.imshow('frame',frame) #if cv2.waitKey(1) & 0xFF == ord('q'): # break except: try: cap = cv2.VideoCapture(gstcmd, cv2.CAP_GSTREAMER) except: print("rtsp connection is down %d..." % (count)) # When everything done, release the capture cap.release() cv2.destroyAllWindows()

Wednesday, 18 October 2023

Wednesday, 6 September 2023

How to allow standard os user to add or remove a wifi without sudo?

 ref: https://askubuntu.com/questions/141553/how-to-enable-wireless-network-for-standard-users


Tuesday, 15 August 2023

how to check or modify the network card speed in ubuntu?

ref: https://phoenixnap.com/kb/ethtool-command-change-speed-duplex-ethernet-card-linux

sudo apt install ethtool

sudo ethtool enp4s0 

sudo ethtool -s enp4s0 autoneg on speed 1000 duplex full

sudo ethtool enp4s0 


Settings for enp4s0:

Supported ports: [ TP ]

Supported link modes:   10baseT/Half 10baseT/Full 

                        100baseT/Half 100baseT/Full 

                        1000baseT/Full 

Supported pause frame use: Symmetric Receive-only

Supports auto-negotiation: Yes

Supported FEC modes: Not reported

Advertised link modes:  10baseT/Half 10baseT/Full 

                        100baseT/Half 100baseT/Full 

                        1000baseT/Full 

Advertised pause frame use: No

Advertised auto-negotiation: Yes

Advertised FEC modes: Not reported

Link partner advertised link modes:  10baseT/Half 10baseT/Full 

                                     100baseT/Half 100baseT/Full 

                                     1000baseT/Full 

Link partner advertised pause frame use: No

Link partner advertised auto-negotiation: Yes

Link partner advertised FEC modes: Not reported

Speed: 10Mb/s

Duplex: Full

Port: Twisted Pair

PHYAD: 0

Transceiver: internal

Auto-negotiation: on

MDI-X: Unknown

Supports Wake-on: pumbg

Wake-on: g

Current message level: 0x00000033 (51)

       drv probe ifdown ifup

Link detected: yes


Wednesday, 2 August 2023

How to check ping able IP address in total using a bash script?

Create a bash script as following:-

#!/bin/bash
# Array of IP addresses to ping
ip_addresses=(
192.168.1.1
192.168.1.2
192.168.1.3
)
# Variables to count successful and unsuccessful pings
ping_success=0
ping_fail=0
# Function to perform the ping and update the counters
ping_ips() {
for ip in "${ip_addresses[@]}"; do
ping -c 1 "$ip" > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Ping to $ip succeeded"
((ping_success++))
else
echo "Ping to $ip failed"
((ping_fail++))
fi
done
}
# Call the function
ping_ips
# Print the results
echo "Total IPs: ${#ip_addresses[@]}"
echo "Ping Success: $ping_success"
echo "Ping Fail: $ping_fail"

Thursday, 22 June 2023

How to change the docker default gateway and ip?

ref: chatgpt

To change the gateway IP address for an NGINX Docker container, you can make use of Docker's network functionality. Follow these steps:

  1. Find the name or ID of the Docker network associated with your NGINX container. You can use the docker network ls command to list the available networks and identify the one that your container is connected to.

  2. Use the docker network inspect command to retrieve detailed information about the network. Replace <network-name> with the name or ID of the network from the previous step. For example:

    • docker network inspect <network-name>
  3. Look for the "Containers" section in the output of the docker network inspect command. Find the entry that corresponds to your NGINX container. Note down the "Container ID" value.
  4. Stop the NGINX container using the docker stop command. Replace <container-id> with the Container ID obtained in the previous step:
    • docker stop <container-id>
  5. Disconnect the NGINX container from the network using the docker network disconnect command. Replace <network-name> and <container-id> with the appropriate values:
    • docker network disconnect <network-name> <container-id>
  6. Create a new network with the desired gateway IP address using the docker network create command. Replace <new-network-name> and <new-gateway-ip> with your desired values:
    • docker network create --subnet=<new-gateway-ip>/16 --gateway=<new-gateway-ip> <new-network-name>
  7. Reconnect the NGINX container to the new network using the docker network connect command. Replace <new-network-name> and <container-id> with the appropriate values: 
    • docker network connect <new-network-name> <container-id>
  8. Start the NGINX container again:
    • docker start <container-id>

After following these steps, your NGINX container should be connected to the new network with the specified gateway IP address. Please note that this approach assumes you have administrative privileges and sufficient Docker knowledge to manage networks and containers.