Packet capture optionsfrom your (rooted) Android device - wifi or 3G● apps - eg Shark for Root● tcpdump - via shell
Packet capture optionsfrom your router or another device on thenetwork (if promiscuous mode) - wifi only● tcpdump/libpcap● wireshark/tshark● pcapy● ngrep
Hackable routersThere are many devices and firmwares tochoose from (see dd-wrt and tomato-usb)I have Netgear WNR3500L with Tomato-USB● ssh built in● Additional packages installed using Optware ○ http://tomatousb.org/doc:optware ○ Includes python, tshark, ngrep, wget, some build tools, ...
Initial capture using tsharktshark -i eth1 -w capture.pcap -f"host 192.168.1.106 and(port 9400 or port 9500)"
PipesPiping data into Python is easyYou can read stdin...import syswhile True: l = sys.stdin.readline():Alternatively use the Unix-like fileinputmodule...import fileinputfor line in fileinput.input():... fileinput reads from a list of files, or else stdin
Now for some poker smartsLoads of resources on the web● Poker games generally ○ starting hand rankings ○ odds calculations etc
Now for some poker smartsEasy lookup tables in python...# Unprocessed space separated string dumpstats_rankings = """AA 2.3200 550,632KK 1.6700 551,878... lots more lines32s -0.1600 369,182"""# Now convert to structured datastats_rankings = dict([ (line.split(), (rank + 1, float(line.split()))) for rank, line in enumerate(stats_rankings.split("n"))])
Now for some poker smartsPython specific● pypoker-eval ○ Wrapper for poker-eval toolkit ○ Run hand simulations● machine learning systems ○ endless possibilities● Lots of other resources at: http://pokerai.org/pf3/viewforum.php?f=32
Codedef read_raw_from_stdin(): line = while 1: l = sys.stdin.readline() line += l.strip() if we have a complete line: parse_update(line) line = if __name__ == "__main__": read_raw_from_stdin()
Codedef parse_update(update_str): player_cards = get_cards(update_str) if player_cards: my_cards = [v for v in player_cards if v != __] if my_cards: rank_starting_hand(my_cards) else: player_cards = old_player_cards # global state excluded community_cards = get_cards(update_str, player=False) if community_cards: print("Community cards %s" % community_cards) rank_hand(player_cards, community_cards)
Codee = PokerEval()def rank_hand(pocket_cards, community_cards, iterations=100000): unknown_cards = [__] * (5 - len(community_cards)) result = e.poker_eval(game = "holdem", pockets = pocket_cards, iterations = iterations, board = community_cards + unknown_cards) for i, data in enumerate(result[eval]): print(pocket_cards[i], "%2d%%" % (float(data[ev]) /10), data[winhi], data[losehi], data[tiehi])
Game in progress - poker-buddy.pyPlayer cards [[__, __], [__, __], [Ac, Kc],[__, __], [__, __]]Group 1(5, 0.77)
Summary● Python can be used for packet capture ○ pycapy● Python for data processing ○ Pipes, unbuffered input (-u option), stdin, fileinput module● Python on embedded devices ○ Optware on routers & other embedded devices● IPython Notebook great for analysis... ...and documenting what you found● Theres a library for almost everything ○ eg pypoker-eval
Thanks! Questions?Code (warts and all):https://github.com/mindsocket/poker-buddy