TeamviewerVpn-s7SiemensPLC-.../teamviewer-troubleshoot.sh

358 lines
9.6 KiB
Bash
Raw Normal View History

2026-02-16 19:36:31 +00:00
#!/bin/bash
#========================================
# TeamViewer VPN - Troubleshooting Script
# Diagnoses common connectivity issues
#========================================
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo ""
echo "========================================"
echo "TeamViewer VPN - Troubleshooting Tool"
echo "========================================"
echo ""
# Function to check status
check_status() {
if [ $1 -eq 0 ]; then
echo -e "${GREEN}✓ PASS${NC}"
return 0
else
echo -e "${RED}✗ FAIL${NC}"
return 1
fi
}
# Counter for issues
ISSUES=0
#========================================
# Test 1: TeamViewer Installation
#========================================
echo -e "${BLUE}[Test 1/12] TeamViewer Installation${NC}"
echo -n " Checking if TeamViewer is installed... "
if command -v teamviewer &> /dev/null; then
check_status 0
VERSION=$(teamviewer --version 2>/dev/null || echo "Unknown")
echo " Version: $VERSION"
else
check_status 1
ISSUES=$((ISSUES + 1))
echo -e " ${YELLOW}Solution: Install TeamViewer from https://www.teamviewer.com${NC}"
fi
#========================================
# Test 2: TeamViewer Service
#========================================
echo ""
echo -e "${BLUE}[Test 2/12] TeamViewer Service Status${NC}"
echo -n " Checking if TeamViewer daemon is running... "
if systemctl is-active --quiet teamviewerd 2>/dev/null; then
check_status 0
elif pgrep -x "TeamViewer" > /dev/null 2>&1; then
check_status 0
echo " Note: Running as user process"
else
check_status 1
ISSUES=$((ISSUES + 1))
echo -e " ${YELLOW}Solution: Start TeamViewer with: sudo systemctl start teamviewerd${NC}"
fi
#========================================
# Test 3: Internet Connectivity
#========================================
echo ""
echo -e "${BLUE}[Test 3/12] Internet Connectivity${NC}"
echo -n " Checking internet connection... "
if ping -c 1 -W 2 8.8.8.8 &> /dev/null; then
check_status 0
else
check_status 1
ISSUES=$((ISSUES + 1))
echo -e " ${YELLOW}Solution: Check your internet connection${NC}"
fi
#========================================
# Test 4: TeamViewer VPN Adapter
#========================================
echo ""
echo -e "${BLUE}[Test 4/12] TeamViewer VPN Adapter${NC}"
echo -n " Checking for TeamViewer VPN interface... "
TV_INTERFACE=$(ip link show | grep -oP "teamviewer\w+" | head -n1)
if [ -n "$TV_INTERFACE" ]; then
check_status 0
echo " Interface found: $TV_INTERFACE"
# Get VPN IP
VPN_IP=$(ip addr show $TV_INTERFACE 2>/dev/null | grep "inet " | awk '{print $2}' | cut -d'/' -f1)
if [ -n "$VPN_IP" ]; then
echo " VPN IP: $VPN_IP"
fi
else
check_status 1
ISSUES=$((ISSUES + 1))
echo -e " ${YELLOW}Solution: Establish TeamViewer VPN connection first${NC}"
echo " 1. Open TeamViewer"
echo " 2. Enter remote PC's TeamViewer ID"
echo " 3. Select 'VPN' instead of 'Remote Control'"
fi
#========================================
# Test 5: VPN Connection
#========================================
echo ""
echo -e "${BLUE}[Test 5/12] VPN Connection Test${NC}"
if [ -n "$VPN_IP" ]; then
read -p " Enter remote gateway VPN IP (or press Enter to skip): " REMOTE_VPN_IP
if [ -n "$REMOTE_VPN_IP" ]; then
echo -n " Pinging remote VPN gateway ($REMOTE_VPN_IP)... "
if ping -c 2 -W 2 $REMOTE_VPN_IP &> /dev/null; then
check_status 0
else
check_status 1
ISSUES=$((ISSUES + 1))
echo -e " ${YELLOW}Solution: Check VPN connection and firewall on remote PC${NC}"
fi
else
echo " Skipped"
fi
else
echo " Skipped (no VPN adapter found)"
fi
#========================================
# Test 6: IP Forwarding
#========================================
echo ""
echo -e "${BLUE}[Test 6/12] IP Forwarding (Gateway only)${NC}"
read -p " Is this PC acting as a gateway? (y/n): " IS_GATEWAY
if [[ "$IS_GATEWAY" =~ ^[Yy]$ ]]; then
echo -n " Checking IP forwarding... "
IP_FORWARD=$(cat /proc/sys/net/ipv4/ip_forward 2>/dev/null)
if [ "$IP_FORWARD" == "1" ]; then
check_status 0
else
check_status 1
ISSUES=$((ISSUES + 1))
echo -e " ${YELLOW}Solution: Enable with: sudo sysctl -w net.ipv4.ip_forward=1${NC}"
fi
else
echo " Skipped (not a gateway)"
fi
#========================================
# Test 7: Routing Table
#========================================
echo ""
echo -e "${BLUE}[Test 7/12] Routing Table${NC}"
read -p " Enter PLC network to check (e.g., 192.168.10.0/24) or press Enter to skip: " PLC_NETWORK
if [ -n "$PLC_NETWORK" ]; then
echo -n " Checking route to $PLC_NETWORK... "
if ip route show | grep -q "$PLC_NETWORK"; then
check_status 0
echo " Route found:"
ip route show | grep "$PLC_NETWORK"
else
check_status 1
ISSUES=$((ISSUES + 1))
echo -e " ${YELLOW}Solution: Add route with: sudo ip route add $PLC_NETWORK via <remote_vpn_ip>${NC}"
fi
else
echo " Skipped"
fi
#========================================
# Test 8: PLC Connectivity
#========================================
echo ""
echo -e "${BLUE}[Test 8/12] PLC Network Connectivity${NC}"
read -p " Enter PLC IP to test (or press Enter to skip): " PLC_IP
if [ -n "$PLC_IP" ]; then
echo -n " Pinging PLC ($PLC_IP)... "
if ping -c 2 -W 2 $PLC_IP &> /dev/null; then
check_status 0
else
check_status 1
ISSUES=$((ISSUES + 1))
echo -e " ${YELLOW}Possible causes:${NC}"
echo " - Route not configured correctly"
echo " - PLC is offline or not at this IP"
echo " - Firewall blocking traffic on gateway"
fi
else
echo " Skipped"
fi
#========================================
# Test 9: S7 Communication Port
#========================================
echo ""
echo -e "${BLUE}[Test 9/12] S7 Communication Port (TCP 102)${NC}"
if [ -n "$PLC_IP" ]; then
echo -n " Checking port 102 on $PLC_IP... "
if command -v nc &> /dev/null; then
if nc -zv -w 2 $PLC_IP 102 2>&1 | grep -q "succeeded\|open"; then
check_status 0
else
check_status 1
ISSUES=$((ISSUES + 1))
echo -e " ${YELLOW}Possible causes:${NC}"
echo " - PLC not configured for remote access"
echo " - PLC firewall settings"
echo " - Wrong IP address"
fi
else
echo "Skipped (netcat not installed)"
fi
else
echo " Skipped (no PLC IP provided)"
fi
#========================================
# Test 10: Firewall Rules (Gateway)
#========================================
echo ""
echo -e "${BLUE}[Test 10/12] Firewall Rules (Gateway only)${NC}"
if [[ "$IS_GATEWAY" =~ ^[Yy]$ ]]; then
echo -n " Checking iptables FORWARD rules... "
if sudo iptables -L FORWARD -n | grep -q "ACCEPT"; then
check_status 0
echo " Current FORWARD chain:"
sudo iptables -L FORWARD -n | head -10
else
check_status 1
ISSUES=$((ISSUES + 1))
echo -e " ${YELLOW}Solution: Add FORWARD rules for TeamViewer VPN interface${NC}"
fi
else
echo " Skipped (not a gateway)"
fi
#========================================
# Test 11: DNS Resolution
#========================================
echo ""
echo -e "${BLUE}[Test 11/12] DNS Resolution${NC}"
echo -n " Checking DNS... "
if host google.com &> /dev/null || nslookup google.com &> /dev/null; then
check_status 0
else
check_status 1
ISSUES=$((ISSUES + 1))
echo -e " ${YELLOW}Solution: Check DNS settings in /etc/resolv.conf${NC}"
fi
#========================================
# Test 12: TUN/TAP Module (Linux)
#========================================
echo ""
echo -e "${BLUE}[Test 12/12] TUN/TAP Kernel Module${NC}"
echo -n " Checking if tun module is loaded... "
if lsmod | grep -q "^tun"; then
check_status 0
else
check_status 1
ISSUES=$((ISSUES + 1))
echo -e " ${YELLOW}Solution: Load module with: sudo modprobe tun${NC}"
fi
#========================================
# Summary
#========================================
echo ""
echo "========================================"
echo "Troubleshooting Summary"
echo "========================================"
echo ""
if [ $ISSUES -eq 0 ]; then
echo -e "${GREEN}✓ All tests passed!${NC}"
echo "Your TeamViewer VPN setup appears to be working correctly."
else
echo -e "${RED}✗ Found $ISSUES issue(s)${NC}"
echo "Please review the solutions above and fix the issues."
fi
echo ""
echo "Additional Information:"
echo "-----------------------"
# Show all network interfaces
echo ""
echo "Network Interfaces:"
ip addr show | grep -E "^[0-9]+:|inet "
# Show routing table
echo ""
echo "Routing Table:"
ip route show
# Show iptables if gateway
if [[ "$IS_GATEWAY" =~ ^[Yy]$ ]]; then
echo ""
echo "Firewall NAT Rules:"
sudo iptables -t nat -L POSTROUTING -n -v | head -20
echo ""
echo "Firewall FORWARD Rules:"
sudo iptables -L FORWARD -n -v | head -20
fi
# TeamViewer info
echo ""
echo "TeamViewer Information:"
if command -v teamviewer &> /dev/null; then
teamviewer info 2>/dev/null || echo "TeamViewer not running or info unavailable"
fi
echo ""
echo "========================================"
echo "Troubleshooting Complete"
echo "========================================"
echo ""
echo "For more help, see:"
echo " - TeamViewer documentation: https://www.teamviewer.com/en/documents/"
echo " - README guide: teamviewer-vpn-plc-access-guide.md"
echo ""