Commits

DaLynX  committed 54c7369

Fix : serverList reinitialized at the wrong place plus minor modifications

  • Participants
  • Parent commits e1ab21b

Comments (0)

Files changed (1)

File SteamList.py

     endOfList = False
     sock  = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     sock.bind((lIP, lPort))
+    serverList = list()
     while not endOfList:
         print 'New block : [last IP : '+lastIP+']'
         sock.sendto(header+lastIP+sz+filter+sz, (rIP, rPort))
         else:
             print 'Invalid server response'
             sys.exit(1)
-        serverList = list()
         unpacker = struct.Struct('4BH')
-        try:
-            i = 0
-            while True:
-                i += 6
+        i = 0
+        while True:
+            i += 6
+            try:
                 rawServerInfo = unpacker.unpack_from(data, i)
-                serverList.append('%d.%d.%d.%d:%d' % rawServerInfo)
-        except struct.error:
-            pass
+            except struct.error:
+                break
+            serverList.append('%d.%d.%d.%d:%d' % rawServerInfo)
         print serverList
         print data[i:]
         prevIP = lastIP
             print 'Looping on same IP'
             break
     f = open('SteamServerList.lst', 'w')
-    f.writelines(serverList)
+    for server in serverList:
+        f.write(server+'\n')
     f.close()