本文整理汇总了Python中socket.getservbyport函数的典型用法代码示例。如果您正苦于以下问题:Python getservbyport函数的具体用法?Python getservbyport怎么用?Python getservbyport使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getservbyport函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: addport
def addport( csvline, domain=defaultdomain ):
"""
Adds a network port to the FMC
"""
proto,port,name,description = csvline.split(",")
post_data = { "type": "ProtocolPortObject" }
try:
#Checks if proto is a string and a known protocol
socket.getprotobyname( proto )
except:
try:
#Check if protocol is a number
int( protocol ) + 1
except:
raise ValueError( "addport", "ERROR", "Unknown value: {value} for {field} in csv line: {line}".format( value=repr( proto ), field="protocol", line=repr( csvline ) ) )
post_data[ "protocol" ] = proto
try:
portname = socket.getservbyname( port )
except:
try:
portname = socket.getservbyport( port )
except:
raise ValueError( "addport", "ERROR", "Unknown value: {value} for {field} in csv line: {line}".format( value=repr( port ), field="port", line=repr( csvline ) ) )
post_data[ "port" ] = port
post_data[ "overridable" ] = "true"
post_data[ "description" ] = description
post_data[ "name" ] = name
api_path = "/api/fmc_config/v1/domain/" + domain + "/object/protocolportobjects"
json_resp = requesttofmc( api_path, post_data )
objectadded( json_resp [ "name" ], json_resp [ "type" ], json_resp [ "id" ] )
return True
开发者ID:abdulet,项目名称:fwbuilder,代码行数:35,代码来源:csv2firepower.py
示例17: check_apache_running
def check_apache_running(self, apache_service):
"""Checks if Apache service is running on port 80."""
print "Checking Apache service......",
serv_err_msg = health_check_utils.check_service_running(self.NAME,
apache_service)
if not serv_err_msg == "":
self._set_status(0, serv_err_msg)
if 'http' != socket.getservbyport(80):
self._set_status(
0,
"[%s]Error: Apache is not listening on port 80."
% self.NAME)
try:
html = urllib2.urlopen('http://localhost')
content = html.geturl()
if "http://localhost/ods/ods.html" != content:
self._set_status(
0,
"[%s]Error: Compass web is not redirected by Apache.")
except Exception:
self._set_status(
0,
"[%s]Error: Apache is not listening on port 80."
% self.NAME)
return True
开发者ID:XenophobePoppy,项目名称:compass-progress-test,代码行数:27,代码来源:check_apache.py
示例18: print_results
def print_results():
if open_ports is not None:
ports_sorted = sorted(open_ports)
print "PORT STATE SERVICE"
for port in ports_sorted:
intend = " " * (8 - len(str(port)))
try:
service = socket.getservbyport(port)
except:
service = "unknown"
print str(port) + intend + "open" + (" "*5) + service
max_counter = max(windows, linux, mac)
if [windows, linux, mac].count(max_counter) != 1:
print "\nNot enough data to guess the os"
else:
if max_counter == windows:
print "\nThe OS might be Windows"
if max_counter == linux:
print "\nThe OS might be Linux"
if max_counter == mac:
print "\nThe OS might be iOS/MAC"
else:
print "No open ports found"
开发者ID:fawind,项目名称:tcp-scanner,代码行数:29,代码来源:tcp_scanner.py
示例19: find_service_name_tcp
def find_service_name_tcp():
protocol_name = 'tcp'
for port in [80, 25]:
print('Port: {} => service name: {} Protocal: {}'.format(
port,
socket.getservbyport(port, protocol_name),
protocol_name))
开发者ID:mrvon,项目名称:LuaSource,代码行数:7,代码来源:network_5.py
示例20: url_is_local
def url_is_local(arg):
"""
Returns True if the given url points to localhost.
We consider all URLs which explicitly define a port as non-local, because it
looks like someone wants to explicitly use some protocol --
`ssh://localost:2222/` is likely to point at an ssh tunnel.
If, however, the port matches the default port for the given protocol, we
consider it local again -- `ssh://localhost:22/` is most likely a real local
activity.
Note that the schema set operates on substring level, so that we will accept
port 22 for `ssh` and also for `sge+ssh` -- this may break in corner cases
(altough I can't think of any right now).
"""
u = saga.Url(arg)
if not host_is_local(u.host):
return False
# host is local, but what does the port indicate?
if u.port and u.port > 0:
try:
if socket.getservbyport(u.port) in u.schema:
# some non-default port is used -- consider remote
return False
except:
# unknown service port --assume this is non-standard...
return False
# port is not set or points to default port for service
return True
开发者ID:complynx,项目名称:pilot,代码行数:35,代码来源:misc.py
注:本文中的socket.getservbyport函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论