Created
May 3, 2026 10:42
-
-
Save taylor224/8b3ccacf63305e32642f7d9844a32260 to your computer and use it in GitHub Desktop.
ICOM VE-PG4 RoIP Gateway Multicast Communication PoC code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """ | |
| VE-PG4 RoIP Gateway 1 (239.255.255.1:22510, G.711u) 로 1초간 1kHz 비프 송신. | |
| """ | |
| import socket, struct, time, math, sys | |
| MCAST = '239.255.255.1' | |
| PORT = 22510 | |
| SSRC = 0xCAFEBABE | |
| TTL = 32 # 라우터 한두 홉 넘기 위해 | |
| IFACE_IP = sys.argv[1] if len(sys.argv) > 1 else None | |
| def linear_to_ulaw(sample: int) -> int: | |
| BIAS, CLIP = 0x84, 32635 | |
| sign = 0x80 if sample < 0 else 0 | |
| if sample < 0: sample = -sample | |
| if sample > CLIP: sample = CLIP | |
| sample += BIAS | |
| val = (sample >> 7) & 0xFF | |
| seg = 0 | |
| while val > 1 and seg < 7: | |
| val >>= 1; seg += 1 | |
| return (~(sign | (seg << 4) | ((sample >> (seg + 3)) & 0x0F))) & 0xFF | |
| ULAW_TBL = bytes(linear_to_ulaw(s if s < 32768 else s - 65536) for s in range(65536)) | |
| s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
| s.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, TTL) | |
| if IFACE_IP: | |
| s.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF, socket.inet_aton(IFACE_IP)) | |
| print(f"outgoing iface = {IFACE_IP}") | |
| print(f"sending 1s of 1 kHz beep -> {MCAST}:{PORT} TTL={TTL} SSRC=0x{SSRC:08x}") | |
| seq, ts = 0, 0 | |
| for f in range(50): | |
| pcm = bytearray() | |
| for i in range(160): | |
| sample = int(8000 * math.sin(2 * math.pi * 1000 * (f*160 + i) / 8000)) | |
| pcm += struct.pack('<h', sample) | |
| ulaw = bytes(ULAW_TBL[pcm[i*2] | (pcm[i*2+1] << 8)] for i in range(160)) | |
| rtp = struct.pack('!BBHII', 0x80, 0x80 if seq == 0 else 0x00, | |
| seq & 0xFFFF, ts & 0xFFFFFFFF, SSRC) | |
| s.sendto(rtp + ulaw, (MCAST, PORT)) | |
| seq += 1; ts += 160 | |
| time.sleep(0.020) | |
| print("done") |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Send beep for 1 second.
You should set up the bridge for send this signal to other radio.