Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../Demo/rpc
File: rnusersclient.py
# Remote nusers client interface
[0] Fix | Delete
[1] Fix | Delete
import rpc
[2] Fix | Delete
from rpc import Packer, Unpacker, UDPClient, BroadcastUDPClient
[3] Fix | Delete
[4] Fix | Delete
[5] Fix | Delete
class RnusersPacker(Packer):
[6] Fix | Delete
def pack_utmp(self, ui):
[7] Fix | Delete
ut_line, ut_name, ut_host, ut_time = utmp
[8] Fix | Delete
self.pack_string(ut_line)
[9] Fix | Delete
self.pack_string(ut_name)
[10] Fix | Delete
self.pack_string(ut_host)
[11] Fix | Delete
self.pack_int(ut_time)
[12] Fix | Delete
def pack_utmpidle(self, ui):
[13] Fix | Delete
ui_itmp, ui_idle = ui
[14] Fix | Delete
self.pack_utmp(ui_utmp)
[15] Fix | Delete
self.pack_uint(ui_idle)
[16] Fix | Delete
def pack_utmpidlearr(self, list):
[17] Fix | Delete
self.pack_array(list, self.pack_itmpidle)
[18] Fix | Delete
[19] Fix | Delete
[20] Fix | Delete
class RnusersUnpacker(Unpacker):
[21] Fix | Delete
def unpack_utmp(self):
[22] Fix | Delete
ut_line = self.unpack_string()
[23] Fix | Delete
ut_name = self.unpack_string()
[24] Fix | Delete
ut_host = self.unpack_string()
[25] Fix | Delete
ut_time = self.unpack_int()
[26] Fix | Delete
return ut_line, ut_name, ut_host, ut_time
[27] Fix | Delete
def unpack_utmpidle(self):
[28] Fix | Delete
ui_utmp = self.unpack_utmp()
[29] Fix | Delete
ui_idle = self.unpack_uint()
[30] Fix | Delete
return ui_utmp, ui_idle
[31] Fix | Delete
def unpack_utmpidlearr(self):
[32] Fix | Delete
return self.unpack_array(self.unpack_utmpidle)
[33] Fix | Delete
[34] Fix | Delete
[35] Fix | Delete
class PartialRnusersClient:
[36] Fix | Delete
[37] Fix | Delete
def addpackers(self):
[38] Fix | Delete
self.packer = RnusersPacker()
[39] Fix | Delete
self.unpacker = RnusersUnpacker('')
[40] Fix | Delete
[41] Fix | Delete
def Num(self):
[42] Fix | Delete
return self.make_call(1, None, None, self.unpacker.unpack_int)
[43] Fix | Delete
[44] Fix | Delete
def Names(self):
[45] Fix | Delete
return self.make_call(2, None, \
[46] Fix | Delete
None, self.unpacker.unpack_utmpidlearr)
[47] Fix | Delete
[48] Fix | Delete
def Allnames(self):
[49] Fix | Delete
return self.make_call(3, None, \
[50] Fix | Delete
None, self.unpacker.unpack_utmpidlearr)
[51] Fix | Delete
[52] Fix | Delete
[53] Fix | Delete
class RnusersClient(PartialRnusersClient, UDPClient):
[54] Fix | Delete
[55] Fix | Delete
def __init__(self, host):
[56] Fix | Delete
UDPClient.__init__(self, host, 100002, 2)
[57] Fix | Delete
[58] Fix | Delete
[59] Fix | Delete
class BroadcastRnusersClient(PartialRnusersClient, BroadcastUDPClient):
[60] Fix | Delete
[61] Fix | Delete
def __init__(self, bcastaddr):
[62] Fix | Delete
BroadcastUDPClient.__init__(self, bcastaddr, 100002, 2)
[63] Fix | Delete
[64] Fix | Delete
[65] Fix | Delete
def test():
[66] Fix | Delete
import sys
[67] Fix | Delete
if not sys.argv[1:]:
[68] Fix | Delete
testbcast()
[69] Fix | Delete
return
[70] Fix | Delete
else:
[71] Fix | Delete
host = sys.argv[1]
[72] Fix | Delete
c = RnusersClient(host)
[73] Fix | Delete
list = c.Names()
[74] Fix | Delete
for (line, name, host, time), idle in list:
[75] Fix | Delete
line = strip0(line)
[76] Fix | Delete
name = strip0(name)
[77] Fix | Delete
host = strip0(host)
[78] Fix | Delete
print "%r %r %r %s %s" % (name, host, line, time, idle)
[79] Fix | Delete
[80] Fix | Delete
def testbcast():
[81] Fix | Delete
c = BroadcastRnusersClient('<broadcast>')
[82] Fix | Delete
def listit(list, fromaddr):
[83] Fix | Delete
host, port = fromaddr
[84] Fix | Delete
print host + '\t:',
[85] Fix | Delete
for (line, name, host, time), idle in list:
[86] Fix | Delete
print strip0(name),
[87] Fix | Delete
print
[88] Fix | Delete
c.set_reply_handler(listit)
[89] Fix | Delete
all = c.Names()
[90] Fix | Delete
print 'Total Count:', len(all)
[91] Fix | Delete
[92] Fix | Delete
def strip0(s):
[93] Fix | Delete
while s and s[-1] == '\0': s = s[:-1]
[94] Fix | Delete
return s
[95] Fix | Delete
[96] Fix | Delete
test()
[97] Fix | Delete
[98] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function