Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- File: Flex.py
- ================================================
- #!/usr/bin/env python3.7
- import socket
- import re
- def getRadioInfo():
- #required modules: socket, re
- addr = ('255.255.255.255', 4992) # broadcast address explicitly
- s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Create socket
- s.bind(('',4992))
- #Initialize:
- moriginal = s.recvfrom(4096)
- m = str(s.recvfrom(4096))
- #Cleanup values:
- m=re.sub('(.*)discovery_protocol_version','discovery_protocol_version',m) #remove prefix from first key of raw data
- m=re.sub('\', \((.*)','',m) #remove trailing data that does not contain keys
- m=m.replace('\\x00\\x00\\x00\\x00','') #remove trailing data on key gui_client_handles value
- #Initialize Dictionary List
- rInfo = {}
- for varval in m.split(" "):
- varval = list(varval.split("="))
- rInfo[varval[0]]=varval[1]
- s.close() # Close socket
- return rInfo
- File: prtRadioInfo.py
- ================================================
- #!/usr/bin/env python3.7
- import socket
- import re
- from Flex import getRadioInfo
- rInfo = getRadioInfo()
- #Print Dictionary List
- cnt=0
- print ('\n\n{0:3} {1:30} {2}'.format('cnt','Key','Values'))
- for k, v in rInfo.items():
- cnt=cnt+1
- print ('{0:3} {1:30} {2}'.format(cnt,k,v))
- print ('\n\nSample display of value from dictionary list\nIP: ',rInfo['ip'])
- Results:
- ================================================
- cnt Key Values
- 1 discovery_protocol_version 3.0.0.1
- 2 model FLEX-6500
- 3 serial 0000-4055-6500-0000
- 4 version 3.1.8.145
- 5 nickname SCRUB
- 6 callsign SCRUB
- 7 ip 192.168.99.99
- 8 port 4992
- 9 status Available
- 10 inuse_ip 192.168.99.100
- 11 inuse_host scrub.local
- 12 max_licensed_version v3
- 13 radio_license_id 00-00-00-00-00-00
- 14 requires_additional_license 0
- 15 fpc_mac
- 16 wan_connected 1
- 17 licensed_clients 2
- 18 available_clients 1
- 19 max_panadapters 4
- 20 available_panadapters 2
- 21 max_slices 4
- 22 available_slices 2
- 23 gui_client_ips 192.168.99.100
- 24 gui_client_hosts scrub.local
- 25 gui_client_programs SmartSDR-Win
- 26 gui_client_stations SCRUB
- 27 gui_client_handles 0x00000000
- Sample display of value from dictionary list
- IP: 192.168.99.99
Advertisement
Add Comment
Please, Sign In to add comment