当前位置: 首页>>代码示例>>Python>>正文


Python socket.getservbyport函数代码示例

本文整理汇总了Python中socket.getservbyport函数的典型用法代码示例。如果您正苦于以下问题:Python getservbyport函数的具体用法?Python getservbyport怎么用?Python getservbyport使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了getservbyport函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: find_service_name

def find_service_name():
	protocolname = 'tcp'
	for port in [25, 80]:
		print "Port:%s => service name:%s" % \
		(port, socket.getservbyport(port, protocolname))
		print "Port:%s => service name:%s" % \
		(53, socket.getservbyport(53, 'udp'))
开发者ID:Tei320,项目名称:python,代码行数:7,代码来源:1-4+find_service_name.py

示例2: testGetServBy

 def testGetServBy(self):
     eq = self.assertEqual
     # Find one service that exists, then check all the related interfaces.
     # I've ordered this by protocols that have both a tcp and udp
     # protocol, at least for modern Linuxes.
     if sys.platform in ('linux2', 'freebsd4', 'freebsd5', 'freebsd6',
                         'freebsd7', 'darwin'):
         # avoid the 'echo' service on this platform, as there is an
         # assumption breaking non-standard port/protocol entry
         services = ('daytime', 'qotd', 'domain')
     else:
         services = ('echo', 'daytime', 'domain')
     for service in services:
         try:
             port = socket.getservbyname(service, 'tcp')
             break
         except socket.error:
             pass
     else:
         raise socket.error
     # Try same call with optional protocol omitted
     port2 = socket.getservbyname(service)
     eq(port, port2)
     # Try udp, but don't barf it it doesn't exist
     try:
         udpport = socket.getservbyname(service, 'udp')
     except socket.error:
         udpport = None
     else:
         eq(udpport, port)
     # Now make sure the lookup by port returns the same service name
     eq(socket.getservbyport(port2), service)
     eq(socket.getservbyport(port, 'tcp'), service)
     if udpport is not None:
         eq(socket.getservbyport(udpport, 'udp'), service)
开发者ID:249550148,项目名称:gevent,代码行数:35,代码来源:test_socket.py

示例3: find_service_name

def find_service_name():
    print("--- Finding a service name, given the port and protocol ---")	
    protocolname = 'tcp'
    for port in [80, 25, 443]: # iterates over an array
        print "Port: %s => service name: %s" %(port, socket.getservbyport(port, protocolname))
    
    # A UDP protocol port test
    print "Port: %s => service name: %s" %(53, socket.getservbyport(53, 'udp'))
开发者ID:GuanglinDu,项目名称:hello_github,代码行数:8,代码来源:1_4_finding_service_name.py

示例4: find_service_name

def find_service_name():
    protocol = 'tcp'
    for port in [25, 80]:
        service = socket.getservbyport(port, protocol)
        print "Port: %d ==> Service name: %s" %(port, service)

    port = 53
    print "Port: %d ==> Service name: %s" %(port, socket.getservbyport(port, 'udp'))
开发者ID:RanHuang,项目名称:Hello-World,代码行数:8,代码来源:1_4_find_service_name.py

示例5: find_serv_name

def find_serv_name():
    protocolname = 'tcp'
    print('\n')
    for port in [80,8000,8080,25,22,21,20,7]:
        print ("Port: {!s} => service.name {!s}".format(
                port, socket.getservbyport(port,protocolname)))
    print ("Port: {!s} => service.name {!s}".format( 
        53, socket.getservbyport(53, 'udp')))
开发者ID:takukawasaki,项目名称:threading_socket_inPython,代码行数:8,代码来源:findservname.py

示例6: find_service_name

def find_service_name ():
    protocolname = 'tcp'
    for port in [80,25]:
        print "Port : %s => service name: %s" %(port, socket.getservbyport(port, protocolname))

    port = 53
    protocolname = 'udp'
    print "Port: %s => service name : %s" %(port, socket.getservbyport(port, protocolname))
开发者ID:johlim,项目名称:study,代码行数:8,代码来源:1_4_finding_service_name.py

示例7: find_service_name

def find_service_name():
    protocolname = "tcp"
    # try:
    # except :
    # 	print "ERROR"
    for port in range(1, 65535):
        try:
            print "port: %s => service name: %s" % (port, socket.getservbyport(port, protocolname))
        except:
            # print "ERROR"
            pass
    print "port: %s => service name: %s" % (53, socket.getservbyport(53, "udp"))
开发者ID:windard,项目名称:Learn-Python,代码行数:12,代码来源:socket_protocol.py

示例8: _get_network_connections

def _get_network_connections():

    try:
        netstat = subprocess.Popen(["/bin/netstat","-atn"], stdout=subprocess.PIPE, close_fds=True).communicate()[0]
    except:
        netstat = subprocess.Popen(["/usr/sbin/netstat","-atn"], stdout=subprocess.PIPE, close_fds=True).communicate()[0]

    connections = {}
    listen_connections = []    
    established_connections = []

    for line in netstat.split('\n'):
    
        if("tcp" in line or "udp" in line):

            line = re.split(" +", line)

            proto = line[0]
            recvq = line[1]
            sendq = line[2]
            local_address = line[3]
            foreign_address = line[4]
            state = line[5]

            local_address_port = local_address.split(':')[-1:][0]
            foreign_address_port = foreign_address.split(':')[-1:][0]            

            local_address_port_resolved = ""
            foreign_address_port_resolved = ""
 
            if(local_address_port!="*"):
                try:
                    local_address_port_resolved = socket.getservbyport(int(local_address_port))
                except: pass
                
            if(foreign_address_port!="*"):
                try:
                    foreign_address_port_resolved = socket.getservbyport(int(foreign_address_port))
                except: pass
            
            if(state=="LISTEN"):
                listen_connections.append([state, proto, recvq, sendq, local_address, local_address_port, local_address_port_resolved, foreign_address, foreign_address_port, foreign_address_port_resolved] )
                #print state, proto, recvq, sendq, local_address, local_address_port, local_address_port_resolved, foreign_address, foreign_address_port, foreign_address_port_resolved

            if(state=="ESTABLISHED"):
                established_connections.append([state, proto, recvq, sendq, local_address, local_address_port, local_address_port_resolved, foreign_address, foreign_address_port, foreign_address_port_resolved] )
                #print state, proto, recvq, sendq, local_address, local_address_port, local_address_port_resolved, foreign_address, foreign_address_port, foreign_address_port_resolved

    connections['listen'] = listen_connections
    connections['established'] = established_connections
    connections['description'] = "Active Internet Connections (including servers)"

    return connections
开发者ID:step1profit,项目名称:cloudly,代码行数:53,代码来源:agent.py

示例9: service

 def service(self):
     # Resolve ports to their services, if known
     service = "unknown"
     try:
         # Try service of sending peer first
         service = socket.getservbyport(self.src_port)
     except OSError:
         # Resolving the sport did not work, trying dport
         try:
             service = socket.getservbyport(self.dest_port)
         except OSError:
             pass
     return service
开发者ID:cooox,项目名称:python-netflow-v9-softflowd,代码行数:13,代码来源:analyze_json.py

示例10: getServiceNameByPort

def getServiceNameByPort(_port = None):
    if _port != None:
        if isinstance(_port, int):
            #通过端口号获得服务名
            print "Port: %s => Service name: %s" % (_port, socket.getservbyport(_port))
        if isinstance(_port, str):
            #通过服务名获得端口号
            print "Service name: %s => Port: %s" % (_port, socket.getservbyname(_port))
    else:
        for _port in range(100):
            try:
                print "Port: %s => Service name: %s" % (_port, socket.getservbyport(_port))
            except:
                pass
开发者ID:ssdtfarm,项目名称:antoubao,代码行数:14,代码来源:network_programm.py

示例11: scan

def scan(daemon, host, port):
    s = socket.socket()
    protocolname = 'tcp'
    s.settimeout(0.1)
    if s.connect_ex((host, port)) == 0:  
        try:
            print "%4d open => tcp service name: %s" %(port,socket.getservbyport(port,protocolname))
            daemon.trigger.emit("%4d open => tcp service name: %s" %(port,socket.getservbyport(port,protocolname)))
        except:
            print port, 'open => tcp service name: No Found'
            daemon.trigger.emit('%4d open => tcp service name: No Found'%port)
    else:
        pass
    s.close()
开发者ID:windard,项目名称:Port_Scan,代码行数:14,代码来源:GScan.py

示例12: find_service_name

def find_service_name():
    protocolname = "tcp"
    for port in range(20, 40):
        try:
            print "Port: %s => service name: %s" % (port, socket.getservbyport(port, protocolname))
        except socket.error, err_msg:
            print "%s: %s" % (port, err_msg)
开发者ID:ONES2,项目名称:ex_PY,代码行数:7,代码来源:__init__.py

示例13: sendToFaraday

 def sendToFaraday(self, url):
     api = xmlrpc.client.ServerProxy(url)
     for host in self.result['vulnerables']:
         h_id = api.createAndAddHost(host['address'],"")
         i_id = api.createAndAddInterface(
             h_id,
             host['address'],
             "00:00:00:00:00:00",
             host['address'],
             "0.0.0.0",
             "0.0.0.0",
             [],
             "0000:0000:0000:0000:0000:0000:0000:0000",
             "00",
             "0000:0000:0000:0000:0000:0000:0000:0000",
             [],
             "",
             socket.gethostbyaddr(host['address'])[0]
             )
         for port in self.ports:
             s_id = api.createAndAddServiceToInterface(
                 h_id,
                 i_id,
                 socket.getservbyport(int(port)),
                 self.getPortType(),
                 port,
                 "open",
                 "",
                 host['evidence']
                 )
开发者ID:CERTUNLP,项目名称:Kintun,代码行数:30,代码来源:scan.py

示例14: probe_ports

def probe_ports(target, min_port_num, max_port_num, evasive):
    #iterates through ports on a target and tries to establish a socket connection
    #records the ports to which a connection could be established
    open_ports = []

    #typically, will iterate from port 0 to port 65535
    #if evasive mode is enabled, will iterate from port 65535 down to port 0
        #to avoid detection by psdetect.py
    if not evasive:
        port_nums_rng = range(min_port_num, max_port_num + 1)
    else:
        port_nums_rng = range(max_port_num, min_port_num - 1, -1)

    for curr_port_num in port_nums_rng:
        try:
            #record if a connection to curr_port_num can be successfully established
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect( (target, curr_port_num) )
            open_ports.append( (curr_port_num, socket.getservbyport(curr_port_num, 'tcp')) )
            s.close()

        except socket.error:
            #if a connection could not be established, do nothing
            pass

    #return ports in sorted order
    if evasive:
        open_ports.sort()

    return open_ports
开发者ID:ak792,项目名称:Port-Scanner-Detector,代码行数:30,代码来源:port_scanner.py

示例15: scan

	def scan(self,ip):
# 		socket.setdefaulttimeout(0.5)
		try:
			for port in range(1,1024):	
				sock = self.openPort(ip,port)
				if sock:
					service = self.bgrabber(sock)
					if service:
						print "[+] Open: {}: {}".format(port,service.strip())
					else:
						try:
							svc = socket.getservbyport(port)
							print "[+] Open: {}: {}".format(port,svc.strip())
						except:
							print "[+] Open: {}: unknown".format(port)
					sock.close()
#			else:
# 				print "[-] Closed: {}".format(port)

# 		except:
# 			print 'unknown error ... fuck'
# 			pass
#
		except KeyboardInterrupt:
			print "You pressed Ctrl+C"
			sys.exit()
开发者ID:gunjan1111,项目名称:Python,代码行数:26,代码来源:port_chk.py


注:本文中的socket.getservbyport函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。