diff options
author | Roland Knall <roland.knall@br-automation.com> | 2015-12-29 15:35:43 +0100 |
---|---|---|
committer | Stig Bjørlykke <stig@bjorlykke.org> | 2016-01-05 14:41:12 +0000 |
commit | cfd5457ec0575be3b1b8726daf95fdc4da0e50fb (patch) | |
tree | fe3ff5d04d5f0c8d077831b3fb9135ae9520960e /doc/extcap_example.py | |
parent | a7e3ba03ce6eaeebc762322cb1691adeeda46ff8 (diff) |
extcap: Add regular expression validation support
Regular expressions follow the Qt Regex syntax, which is
formulated after the Perl Regex syntax. A more detailed
overview of the possible rules can be found at:
http://doc.qt.io/qt-4.8/qregexp.html
If a required option is present, even the double-click on
the interface will first start the options dialog (Qt only)
Required fields are marked bold and put first in the dialog.
Additionally if validation failes (which it will if a required
field is kept empty, but also if a non-required textfield is
violating the defined regex), the label of the field is marked
with red.
Change-Id: If04a1146d0dfa778332ab2a39122c7a6ee1e93d2
Reviewed-on: https://code.wireshark.org/review/12914
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Diffstat (limited to 'doc/extcap_example.py')
-rwxr-xr-x | doc/extcap_example.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/doc/extcap_example.py b/doc/extcap_example.py index 1eab8d39e4..13c079d0ec 100755 --- a/doc/extcap_example.py +++ b/doc/extcap_example.py @@ -74,9 +74,10 @@ def extcap_config(interface): values = [] args.append ( (0, '--delay', 'Time delay', 'Time delay between packages', 'integer', '{range=1,15}') ) - args.append ( (1, '--message', 'Message', 'Package message content', 'string', '') ) + args.append ( (1, '--message', 'Message', 'Package message content', 'string', '{required=true}') ) args.append ( (2, '--verify', 'Verify', 'Verify package content', 'boolflag', '') ) args.append ( (3, '--remote', 'Remote Channel', 'Remote Channel Selector', 'selector', '')) + args.append ( (4, '--fake_ip', 'Fake IP Address', 'Use this ip address as sender', 'string', '{validation=\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b}')) values.append ( (3, "if1", "Remote1", "true" ) ) values.append ( (3, "if2", "Remote2", "false" ) ) @@ -140,7 +141,7 @@ def ip_checksum(iph): csum = csum & 0xFFFF ^ 0xFFFF return csum -def pcap_fake_package ( message ): +def pcap_fake_package ( message, fake_ip ): pcap = bytearray() #length = 14 bytes [ eth ] + 20 bytes [ ip ] + messagelength @@ -172,13 +173,16 @@ def pcap_fake_package ( message ): pcap = append_bytes(pcap, struct.pack('b', int ( '40', 16) )) pcap = append_bytes(pcap, struct.pack('B', 0xFE )) # Protocol (2 = unspecified) pcap = append_bytes(pcap, struct.pack('<H', int ( '0000', 16) )) # Checksum - pcap = append_bytes(pcap, struct.pack('>L', int ( '7F000001', 16) )) # Source IP + + parts = fake_ip.split('.') + ipadr = (int(parts[0]) << 24) + (int(parts[1]) << 16) + (int(parts[2]) << 8) + int(parts[3]) + pcap = append_bytes(pcap, struct.pack('>L', ipadr )) # Source IP pcap = append_bytes(pcap, struct.pack('>L', int ( '7F000001', 16) )) # Dest IP pcap = append_bytes(pcap, message) return pcap -def extcap_capture(interface, fifo, delay, verify, message, remote): +def extcap_capture(interface, fifo, delay, verify, message, remote, fake_ip): global doExit signal.signal(signal.SIGINT, signalHandler) @@ -198,7 +202,7 @@ def extcap_capture(interface, fifo, delay, verify, message, remote): while doExit == False: out = str( "%s|%04X%s|%s" % ( remote.strip(), len(message), message, verify ) ) try: - fh.write (pcap_fake_package(out)) + fh.write (pcap_fake_package(out, fake_ip)) time.sleep(tdelay) except IOError: doExit = True @@ -216,6 +220,7 @@ if __name__ == '__main__': # Capture options delay = 0 message = "" + fake_ip = "" parser = argparse.ArgumentParser( prog="Extcap Example", @@ -236,6 +241,7 @@ if __name__ == '__main__': parser.add_argument("--delay", help="Demonstrates an integer variable", type=int, default=0, choices=[0, 1, 2, 3, 4, 5] ) parser.add_argument("--remote", help="Demonstrates a selector choice", default="if1", choices=["if1", "if2"] ) parser.add_argument("--message", help="Demonstrates string variable", nargs='?', default="" ) + parser.add_argument("--fake_ip", help="Add a fake sender IP adress", nargs='?', default="127.0.0.1" ) args, unknown = parser.parse_known_args() if ( len(sys.argv) <= 1 ): @@ -260,6 +266,10 @@ if __name__ == '__main__': if ( args.message == None or len(args.message) == 0 ): message = "Extcap Test" + fake_ip = args.fake_ip + if ( args.fake_ip == None or len(args.fake_ip) < 7 or len(args.fake_ip.split('.')) != 4 ): + fake_ip = "127.0.0.1" + if args.extcap_config: extcap_config(interface) elif args.extcap_dlts: @@ -267,7 +277,7 @@ if __name__ == '__main__': elif args.capture: if args.fifo is None: sys.exit(ERROR_FIFO) - extcap_capture(interface, args.fifo, args.delay, args.verify, message, args.remote) + extcap_capture(interface, args.fifo, args.delay, args.verify, message, args.remote, fake_ip) else: usage() sys.exit(ERROR_USAGE) |