#NEWLINE# def _bsd_ranges( ) : #NEWLINE# #INDENT# pp = subprocess . Popen ( [ 'sysctl' , 'net.inet.ip.portrange' ] , stdout = subprocess . PIPE ) #NEWLINE# ( stdout , stderr ) = pp . communicate ( ) #NEWLINE# lines = stdout . decode ( 'ascii' ) . split ( '\n' ) #NEWLINE# out = dict ( [ [ x . strip ( ) . rsplit ( '.' ) [ ( - 1 ) ] for x in l . split ( ':' ) ] for l in lines if l ] ) #NEWLINE# ranges = [ ( 'first' , 'last' ) , ( 'lowfirst' , 'lowlast' ) , ( 'hifirst' , 'hilast' ) , ( 'portfirst' , 'portlast' ) , ( 'porthifirst' , 'porthilast' ) ] #NEWLINE# res = [ ] #NEWLINE# for rng in ranges : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( low , high ) = ( int ( out [ rng [ 0 ] ] ) , int ( out [ rng [ 1 ] ] ) ) #NEWLINE# if ( low <= high ) : #NEWLINE# #INDENT# res . append ( ( low , high ) ) #NEWLINE# #UNINDENT# #UNINDENT# except KeyError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# return res