Help us understand the problem. What is going on with this article?

Ruby で DistIP,DistPort,SourceIP,SourcePort を指定して Tcp 通信を行うコード

きっかけ

通信の検証で5-tupleの影響を受けているのか確認する必要があった

5-tupleとは

IPヘッダに存在する5つの要素のことで

1.Source IP
送信元アドレス
2.Destination IP
宛先アドレス
3.Source Port
送信元ポート
4.Destination Port
宛先ポート
5.Protocol
プロトコル

を指す

tcp.rb
require 'socket'

distIp     = "111.111.111.111"
distPort   = 80
sourceIp   = "222.222.222.222"
sourcePort = 100

begin
  s = TCPSocket.open(distIp,distPort,sourceIp,sourcePort)
  s.print "GET / HTTP/1.0\r\n\r\n"
  print s.read
ensure
  s.close if s
end

メモ

サーバに送信している部分で下記のヘッダー情報が必要かもしれないと思った

tcp.rb
  s.print "GET / HTTP/1.0\r\nUser-Agent: curl/7.19.7\r\nHost: localhost\r\nAccept: */*\r\nConnection: close\r\n\r\n"
Atheist2
Programmer
iij
日本のインターネットを支えてきたIIJ。現在もその先もイニシアティブをとり続けます。
https://www.iij.ad.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした